import 'dart:math';

import 'package:siro_rider/views/widgets/elevated_btn.dart';
import 'package:siro_rider/views/widgets/mycircular.dart';
import 'package:flutter/material.dart';
import 'package:flutter_font_icons/flutter_font_icons.dart';
import 'package:get/get.dart';
import 'package:intaleq_maps/intaleq_maps.dart';
import 'dart:ui';

import '../../../constant/colors.dart';
import '../../../controller/home/map/location_search_controller.dart';
import '../../../controller/home/map/map_engine_controller.dart';
import '../../../controller/home/vip_waitting_page.dart';
import '../navigation/navigation_view.dart';

// --- الدالة الرئيسية بالتصميم الجديد ---
GetBuilder<MapEngineController> leftMainMenuIcons() {
  return GetBuilder<MapEngineController>(
    builder: (controller) {
      final locationSearch = Get.find<LocationSearchController>();
      return Positioned(
        top: Get.height * .01,
        left: 0,
        right: 0,
        child: Center(
          child: ClipRRect(
            borderRadius: BorderRadius.circular(50.0),
            child: BackdropFilter(
              filter: ImageFilter.blur(sigmaX: 8.0, sigmaY: 8.0),
              child: AnimatedContainer(
                duration: const Duration(milliseconds: 300),
                padding: const EdgeInsets.symmetric(horizontal: 8),
                decoration: BoxDecoration(
                  color: AppColor.secondaryColor.withValues(alpha: 0.4),
                  borderRadius: BorderRadius.circular(50.0),
                  border: Border.all(color: AppColor.secondaryColor),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    _buildMapActionButton(
                      icon: Icons.near_me_outlined,
                      tooltip: 'Toggle Map Type',
                      onPressed: () => Get.to(() => NavigationView()),
                    ),
                    _buildVerticalDivider(),
                    _buildMapActionButton(
                      icon: Icons.my_location_rounded,
                      tooltip: 'Go to My Location',
                      onPressed: () {
                        controller.mapController?.animateCamera(
                          CameraUpdate.newLatLng(
                            LatLng(
                              locationSearch.passengerLocation.latitude,
                              locationSearch.passengerLocation.longitude,
                            ),
                          ),
                        );
                      },
                    ),
                    _buildVerticalDivider(),
                    _buildMapActionButton(
                      icon: Octicons.watch,
                      tooltip: 'VIP Waiting Page',
                      onPressed: () => Get.to(() => VipWaittingPage()),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ),
      );
    },
  );
}

Widget _buildMapActionButton({
  required IconData icon,
  required String tooltip,
  required VoidCallback onPressed,
}) {
  return IconButton(
    onPressed: onPressed,
    icon: Icon(icon, color: AppColor.writeColor, size: 22),
    tooltip: tooltip,
    splashRadius: 22,
    padding: const EdgeInsets.all(12),
    constraints: const BoxConstraints(),
  );
}

Widget _buildVerticalDivider() {
  return Container(
    height: 20,
    width: 1,
    color: AppColor.writeColor.withValues(alpha: 0.2),
  );
}

class TestPage extends StatelessWidget {
  const TestPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('iOS Live Activity Test'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            MyCircularProgressIndicator(),
            MyElevatedButton(
              title: 'title',
              onPressed: () {},
            ),
            ElevatedButton(
              style: ElevatedButton.styleFrom(
                backgroundColor: Colors.red,
              ),
              onPressed: () async {},
              child: const Text('End Activity'),
            ),
          ],
        ),
      ),
    );
  }
}
