import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sigap/src/features/auth/presentasion/controllers/signup/step/selfie-verification/face_liveness_detection_controller.dart';

class CountdownOverlayWidget extends StatelessWidget {
  final FaceLivenessController controller;

  const CountdownOverlayWidget({super.key, required this.controller});

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      final isCountdown = controller.status.value == LivenessStatus.countdown;

      if (!isCountdown) {
        return const SizedBox.shrink();
      }

      return _buildMinimalistCountdown(context);
    });
  }

  Widget _buildMinimalistCountdown(BuildContext context) {
    return Positioned.fill(
      child: Center(
        child: Obx(() {
          final countdownValue = controller.countdownSeconds.value;

          return AnimatedSwitcher(
            duration: const Duration(milliseconds: 300),
            transitionBuilder: (Widget child, Animation<double> animation) {
              return ScaleTransition(
                scale: Tween<double>(begin: 0.8, end: 1.0).animate(
                  CurvedAnimation(
                    parent: animation,
                    curve: Curves.easeOutCubic,
                  ),
                ),
                child: FadeTransition(opacity: animation, child: child),
              );
            },
            child: Text(
              '$countdownValue',
              key: ValueKey<int>(countdownValue),
              style: TextStyle(
                color: Colors.white,
                fontWeight: FontWeight.w300,
                fontSize: 120,
                height: 1.0,
                shadows: [
                  Shadow(
                    color: Colors.black.withOpacity(0.3),
                    blurRadius: 8,
                    offset: const Offset(0, 2),
                  ),
                ],
              ),
            ),
          );
        }),
      ),
    );
  }
}
