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

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

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MapDriverController>(
        builder: (mapDriverController) => mapDriverController.isRideStarted
            ? Positioned(
                left: 125,
                bottom: 20,
                child: Container(
                    decoration: AppStyle.boxDecoration,
                    child: IconButton(
                      onPressed: () async {
                        var startLat = Get.find<MapDriverController>()
                            .latLngpassengerLocation
                            .latitude;
                        var startLng = Get.find<MapDriverController>()
                            .latLngpassengerLocation
                            .longitude;

                        var endLat = Get.find<MapDriverController>()
                            .latLngPassengerDestination
                            .latitude;
                        var endLng = Get.find<MapDriverController>()
                            .latLngPassengerDestination
                            .longitude;

                        String url =
                            'https://www.google.com/maps/dir/$startLat,$startLng/$endLat,$endLng/&directionsmode=driving';
                        if (await canLaunchUrl(Uri.parse(url))) {
                          await launchUrl(Uri.parse(url));
                        } else {
                          throw 'Could not launch google maps';
                        }
                      },
                      icon: const Icon(
                        MaterialCommunityIcons.map_marker_radius,
                        size: 45,
                        color: AppColor.blueColor,
                      ),
                    )),
              )
            : const SizedBox());
  }
}
