import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'dart:ui'; // مهم لإضافة تأثير الضبابية

import '../../../constant/colors.dart';
import '../../../constant/style.dart';
import '../../../controller/home/map_passenger_controller.dart';

// --- الويدجت الرئيسية بالتصميم الجديد ---
class PassengerRideLocationWidget extends StatefulWidget {
  const PassengerRideLocationWidget({super.key});

  @override
  State<PassengerRideLocationWidget> createState() =>
      _PassengerRideLocationWidgetState();
}

class _PassengerRideLocationWidgetState
    extends State<PassengerRideLocationWidget>
    with SingleTickerProviderStateMixin {
  late AnimationController _animationController;
  late Animation<double> _animation;

  @override
  void initState() {
    super.initState();
    // --- إعداد الأنيميشن للأيقونة ---
    _animationController = AnimationController(
      vsync: this,
      duration: const Duration(milliseconds: 1200),
    )..repeat(reverse: true); // التكرار بشكل عكسي لإنشاء تأثير النبض

    _animation = Tween<double>(begin: 0.9, end: 1.1).animate(
      CurvedAnimation(parent: _animationController, curve: Curves.easeInOut),
    );
  }

  @override
  void dispose() {
    _animationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MapPassengerController>(builder: (controller) {
      // --- نفس شرط الإظهار الخاص بك ---
      return AnimatedPositioned(
        duration: const Duration(milliseconds: 300),
        curve: Curves.easeOut,
        bottom: controller.isPassengerRideLocationWidget
            ? 20
            : -100, // حركة دخول وخروج ناعمة
        left: 20,
        right: 20,
        child: ClipRRect(
          borderRadius: BorderRadius.circular(50.0), // حواف دائرية بالكامل
          child: BackdropFilter(
            filter: ImageFilter.blur(sigmaX: 8.0, sigmaY: 8.0), // تأثير زجاجي
            child: Container(
              padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 14),
              decoration: BoxDecoration(
                color: AppColor.secondaryColor.withOpacity(0.85),
                borderRadius: BorderRadius.circular(50.0),
                border: Border.all(color: AppColor.writeColor.withOpacity(0.2)),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  // --- أيقونة متحركة لجذب الانتباه ---
                  ScaleTransition(
                    scale: _animation,
                    child: Icon(
                      Icons.location_on,
                      color: AppColor.primaryColor,
                      size: 28,
                    ),
                  ),
                  const SizedBox(width: 12),
                  // --- نص إرشادي واضح ---
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        "Set pickup location".tr,
                        style: AppStyle.title
                            .copyWith(fontWeight: FontWeight.bold),
                      ),
                      Text(
                        "Move the map to adjust the pin".tr,
                        style: AppStyle.subtitle.copyWith(
                          color: AppColor.writeColor.withOpacity(0.7),
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ),
        ),
      );
    });
  }
}
