import 'package:flutter/material.dart'; import 'package:google_sign_in/google_sign_in.dart'; import 'dart:async'; import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; import 'package:pvt15/providers/user_provider.dart'; class ProfilePage extends StatelessWidget { final GoogleSignInAccount? user; const ProfilePage({super.key, required this.user}); static const Color purple = Color(0xFF7A28A5); static const Color pink = Color(0xFFF9377B); static const Color lightPurple = Color(0xFFE6CCF2); Widget _buildInfoRow(BuildContext context, String label, String value) { return Container( margin: const EdgeInsets.symmetric(vertical: 8.0), padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 15), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(25), boxShadow: [ BoxShadow( color: Colors.black.withValues(alpha: 0.2), blurRadius: 5, offset: const Offset(0, 2), ), ], ), child: Row( children: [ Text( label, style: TextStyle( fontSize: 14, color: Colors.grey[700], fontWeight: FontWeight.w500, ), ), const SizedBox(width: 10), Expanded( child: Text( value, textAlign: TextAlign.end, style: const TextStyle( fontSize: 14, fontWeight: FontWeight.bold, color: Colors.black87, ), overflow: TextOverflow.ellipsis, ), ), ], ), ); } @override Widget build(BuildContext context) { final providerUser = Provider.of(context).user; final String username = providerUser?.username ?? 'Gäst'; final name = user?.displayName ?? 'Användare'; final email = user?.email ?? 'Ingen e-post'; final photoUrl = user?.photoUrl; return Scaffold( extendBodyBehindAppBar: true, appBar: AppBar( title: const Text('Profil'), centerTitle: true, backgroundColor: Colors.transparent, elevation: 0, iconTheme: const IconThemeData(color: Colors.white), titleTextStyle: const TextStyle( color: Colors.white, fontSize: 24, fontWeight: FontWeight.bold, ), ), body: Container( decoration: const BoxDecoration( gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [purple, pink], ), ), child: SafeArea( child: Column( children: [ Expanded( child: SingleChildScrollView( padding: const EdgeInsets.all(20.0), child: Container( padding: const EdgeInsets.all(24.0), decoration: BoxDecoration( color: lightPurple.withValues(alpha: 0.7), borderRadius: BorderRadius.circular(30.0), ), child: Column( children: [ CircleAvatar( radius: 60, backgroundColor: Colors.white.withValues(alpha: 0.7), backgroundImage: photoUrl != null ? NetworkImage(photoUrl) : null, child: photoUrl == null ? Icon( Icons.person, size: 60, color: Colors.grey[700], ) : null, ), const SizedBox(height: 16), Text( username, style: const TextStyle( fontSize: 28, fontWeight: FontWeight.bold, color: Colors.black87, ), textAlign: TextAlign.center, ), const SizedBox(height: 24), _buildInfoRow(context, 'Användarnamn', username), _buildInfoRow(context, 'E-post', email), _buildInfoRow(context, 'Namn', name), ], ), ), ), ), Padding( padding: const EdgeInsets.all(20.0), child: Column( children: [ SizedBox( width: double.infinity, child: ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: Colors.white, padding: const EdgeInsets.symmetric(vertical: 15), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(30), ), foregroundColor: pink, ), onPressed: () async { try { await GoogleSignIn().signOut(); Navigator.of( context, ).popUntil((route) => route.isFirst); } catch (error) { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text( 'Utloggning misslyckades: $error', ), ), ); } }, child: const Text( 'Logga ut', style: TextStyle( fontSize: 18, fontWeight: FontWeight.bold, ), ), ), ), TextButton( onPressed: () { int countDown = 5; Timer? timer; showDialog( context: context, builder: (dialogContext) { return StatefulBuilder( builder: ( BuildContext context, StateSetter setState, ) { timer ??= Timer.periodic( const Duration(seconds: 1), (t) { if (countDown > 0) { HapticFeedback.lightImpact(); setState(() { countDown--; }); } else { t.cancel(); } }, ); return AlertDialog( title: const Text('Avsluta konto'), content: const Text( 'Är du helt säker på att du vill avsluta ditt konto? Denna åtgärd kan inte ångras.', ), actions: [ TextButton( child: const Text('Avbryt'), onPressed: () { timer?.cancel(); Navigator.pop(dialogContext); }, ), TextButton( onPressed: countDown > 0 ? null : () { timer?.cancel(); Navigator.pop(dialogContext); ScaffoldMessenger.of( context, ).showSnackBar( const SnackBar( content: Text( 'Avsluta konto grejer', ), ), ); }, child: Text( countDown > 0 ? 'Vänta ${countDown}s...' : 'Avsluta konto', style: TextStyle( color: countDown > 0 ? Colors.grey : Colors.redAccent, ), ), ), ], ); }, ); }, ).then((_) { timer?.cancel(); }); }, child: const Text( 'Avsluta konto', style: TextStyle( color: Colors.black87, fontSize: 16, fontWeight: FontWeight.w600, ), ), ), ], ), ), ], ), ), ), ); } }