import 'package:flutter/material.dart';

import 'package:provider/provider.dart';

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

import 'package:pweb/app/router/pages.dart';

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


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

  @override
  Widget build(BuildContext context) {
    return ListTile(
      leading: const Icon(Icons.logout),
      title: Text(AppLocalizations.of(context)!.navigationLogout),
      onTap: () => _logout(context),
    );
  }

  void _logout(BuildContext context) {
    Navigator.pop(context); 
    final accountProvider = Provider.of<AccountProvider>(context, listen: false);
    accountProvider.logout();
    navigateAndReplace(context, Pages.login);
  }
}
