import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intaleq_maps/intaleq_maps.dart';
import 'package:sefer_driver/constant/api_key.dart';

import '../../../../controller/functions/location_controller.dart';
import '../../../../controller/home/captin/map_driver_controller.dart';
import '../../../../controller/profile/setting_controller.dart';

class GoogleDriverMap extends StatelessWidget {
  const GoogleDriverMap({
    super.key,
    required this.locationController,
  });

  final LocationController locationController;

  @override
  Widget build(BuildContext context) {
    final MapDriverController controller = Get.put(MapDriverController());

    // New: تحديد قيمة الـ padding لتحريك مركز الخريطة للأعلى
    final double mapPaddingBottom = MediaQuery.of(context).size.height * 0.3;

    return GetBuilder<MapDriverController>(
      builder: (controller) => IntaleqMap(
        apiKey: AK.mapAPIKEY,
        onMapCreated: (mapController) {
          controller.onMapCreated(mapController);
        },
        mapType: Get.isRegistered<SettingController>()
            ? (Get.find<SettingController>().isMapDarkMode
                ? IntaleqMapType.normal
                : IntaleqMapType.light)
            : IntaleqMapType.light,
        zoomControlsEnabled: false,
        initialCameraPosition: CameraPosition(
          target: locationController.myLocation,
          zoom: 17,
          bearing: locationController.heading,
          tilt: 60,
        ),
        // padding: EdgeInsets.only(bottom: 50, top: Get.height * 0.7),
        // minMaxZoomPreference: const MinMaxZoomPreference(8, 18),
        myLocationEnabled: false,
        myLocationButtonEnabled: true,
        compassEnabled: true,
        polylines: controller.polyLines.toSet(),
        markers: {
          Marker(
            markerId: MarkerId('MyLocation'.tr),
            position: controller.smoothedLocation ?? locationController.myLocation,
            rotation: controller.smoothedHeading,
            flat: true,
            anchor: const Offset(0.5, 0.5),
            icon: controller.carIcon,
          ),
          Marker(
            markerId: MarkerId('start'.tr),
            position: controller.latLngPassengerLocation,
            icon: controller.startIcon,
          ),
          Marker(
            markerId: MarkerId('end'.tr),
            position: controller.latLngPassengerDestination,
            icon: controller.endIcon,
          ),
        },
      ),
    );
  }
}
