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

import '../../../../constant/api_key.dart';
import '../../../../controller/functions/location_controller.dart';
import '../../../../controller/home/captin/home_captain_controller.dart';

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

  @override
  Widget build(BuildContext context) {
    final LocationController locationController =
        Get.find<LocationController>();
    final HomeCaptainController homeCaptainController =
        Get.find<HomeCaptainController>();

    return Obx(() {
      final LatLng currentLocation = LatLng(
          locationController.myLocation.latitude,
          locationController.myLocation.longitude);
      final double currentHeading = locationController.heading;

      return IntaleqMap(
        apiKey: AK.mapSaasKey,
        initialCameraPosition: CameraPosition(
          target: currentLocation,
          zoom: 15,
          bearing: currentHeading,
        ),
        markers: {
          Marker(
            markerId: const MarkerId('myLocation'),
            position: currentLocation,
            rotation: currentHeading,
            icon: homeCaptainController.carIcon,
            anchor: const Offset(0.5, 0.5),
            flat: true,
            zIndex: 2,
          )
        },
        onMapCreated: (IntaleqMapController controller) {
          // You can assign this controller if needed
        },
      );
    });
  }
}

