import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../../constant/colors.dart';
import '../../../../constant/style.dart';
import '../../../../controller/home/captin/map_driver_controller.dart';

// ويدجت للعرض فقط (بدون منطق فتح نوافذ)
class SpeedCircle extends StatelessWidget {
  const SpeedCircle({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MapDriverController>(
      id: 'SpeedCircle', // نحدد ID للتحديث الخفيف
      builder: (controller) {
        // إذا السرعة 0 أو أقل، نخفي الدائرة
        if (controller.speed <= 0) return const SizedBox();

        bool isSpeeding = controller.speed > 100;

        return Positioned(
          left: 20,
          top: 100, // مكانها المناسب
          child: Container(
            width: 70,
            height: 70,
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              color: Colors.white,
              boxShadow: [
                BoxShadow(
                  color: Colors.black.withOpacity(0.2),
                  blurRadius: 10,
                  offset: const Offset(0, 4),
                )
              ],
              border: Border.all(
                color: _getSpeedColor(controller.speed),
                width: 4,
              ),
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  controller.speed.toStringAsFixed(0),
                  style: TextStyle(
                    fontFamily: AppStyle.title.fontFamily,
                    fontSize: 22,
                    fontWeight: FontWeight.w900,
                    height: 1.0,
                    color: Colors.black87,
                  ),
                ),
                Text(
                  "km/h",
                  style: TextStyle(
                    fontSize: 10,
                    fontWeight: FontWeight.bold,
                    color: Colors.grey,
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  Color _getSpeedColor(double speed) {
    if (speed < 60) return AppColor.greenColor;
    if (speed < 100) return Colors.orange;
    return Colors.red;
  }
}
