import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../../core/providers/auth_provider.dart'; class EmployeeLoginScreen extends ConsumerStatefulWidget { const EmployeeLoginScreen({super.key}); @override ConsumerState createState() => _EmployeeLoginScreenState(); } class _EmployeeLoginScreenState extends ConsumerState { final _formKey = GlobalKey(); final _emailController = TextEditingController(); final _passwordController = TextEditingController(); bool _obscurePassword = true; bool _loading = false; String? _error; @override void dispose() { _emailController.dispose(); _passwordController.dispose(); super.dispose(); } Future _login() async { if (!_formKey.currentState!.validate()) return; setState(() { _loading = true; _error = null; }); try { await ref.read(authProvider.notifier).loginEmployee( _emailController.text.trim(), _passwordController.text, ); } catch (e) { setState(() { _error = 'Invalid email or password. Please try again.'; }); } finally { if (mounted) setState(() => _loading = false); } } @override Widget build(BuildContext context) { return Scaffold( body: SafeArea( child: SingleChildScrollView( padding: const EdgeInsets.all(24), child: Form( key: _formKey, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const SizedBox(height: 32), IconButton( onPressed: () => Navigator.of(context).pop(), icon: const Icon(Icons.arrow_back), padding: EdgeInsets.zero, ), const SizedBox(height: 24), const Text( 'Employee Login', style: TextStyle( fontSize: 28, fontWeight: FontWeight.bold, color: Color(0xFF111928), ), ), const SizedBox(height: 8), const Text( 'Sign in to your company dashboard', style: TextStyle(fontSize: 15, color: Color(0xFF6B7280)), ), const SizedBox(height: 40), if (_error != null) ...[ Container( padding: const EdgeInsets.all(12), decoration: BoxDecoration( color: const Color(0xFFFDE8E8), borderRadius: BorderRadius.circular(10), ), child: Row( children: [ const Icon(Icons.error_outline, color: Color(0xFFE02424), size: 18), const SizedBox(width: 8), Expanded( child: Text( _error!, style: const TextStyle( color: Color(0xFF9B1C1C), fontSize: 13, ), ), ), ], ), ), const SizedBox(height: 20), ], TextFormField( controller: _emailController, keyboardType: TextInputType.emailAddress, textInputAction: TextInputAction.next, decoration: const InputDecoration( labelText: 'Email', prefixIcon: Icon(Icons.email_outlined), ), validator: (v) => (v == null || !v.contains('@')) ? 'Enter a valid email' : null, ), const SizedBox(height: 16), TextFormField( controller: _passwordController, obscureText: _obscurePassword, textInputAction: TextInputAction.done, onFieldSubmitted: (_) => _login(), decoration: InputDecoration( labelText: 'Password', prefixIcon: const Icon(Icons.lock_outline), suffixIcon: IconButton( icon: Icon(_obscurePassword ? Icons.visibility_outlined : Icons.visibility_off_outlined), onPressed: () => setState( () => _obscurePassword = !_obscurePassword), ), ), validator: (v) => (v == null || v.isEmpty) ? 'Password is required' : null, ), const SizedBox(height: 32), SizedBox( width: double.infinity, child: ElevatedButton( onPressed: _loading ? null : _login, child: _loading ? const SizedBox( height: 20, width: 20, child: CircularProgressIndicator( strokeWidth: 2, valueColor: AlwaysStoppedAnimation(Colors.white), ), ) : const Text('Sign In'), ), ), ], ), ), ), ), ); } }