import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controllers/biometric_controller.dart';

class BiometricAuthView extends StatefulWidget {
  const BiometricAuthView({super.key});

  @override
  State<BiometricAuthView> createState() => _BiometricAuthViewState();
}

class _BiometricAuthViewState extends State<BiometricAuthView> {
  final BiometricController controller = Get.put(BiometricController());

  @override
  void initState() {
    super.initState();
    // Auto trigger biometric prompt after view is rendered
    WidgetsBinding.instance.addPostFrameCallback((_) {
      controller.authenticateAndGoToDashboard();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Icon(Icons.lock_outline, size: 80, color: Color(0xFF0F4C81)),
            const SizedBox(height: 24),
            const Text(
              'التحقق من الهوية',
              style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 16),
            const Text('الرجاء استخدام البصمة لإلغاء القفل'),
            const SizedBox(height: 48),
            Obx(() => controller.isAuthenticating.value 
              ? const CircularProgressIndicator()
              : IconButton(
                  icon: const Icon(Icons.fingerprint, size: 64, color: Color(0xFF0F4C81)),
                  onPressed: () => controller.authenticateAndGoToDashboard(),
                )
            ),
          ],
        ),
      ),
    );
  }
}
