using GMCabsDriverAssistant.Services;
using GMCabsDriverAssistant.UserControl.ViewModels;
using GMCabsDriverAssistant.ViewModels;
using GMCabsDriverAssistantSolution.Views;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
//using Xamarin.CommunityToolkit.Extensions;
using Microsoft.Maui;
using Microsoft.Maui.Controls;

namespace GMCabsDriverAssistant.UserControl
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class TripInformationPage : ContentView
    {
        [Browsable(true)]
        [Category("Action")]
        [Description("Invoked when user clicks button")]
        public event BluetoothStatusChanged BluetoothStatusUpdated;

        public string BluetoothConnectionStatusText
        {
            get => _viewModel.BluetoothConnectionStatusText;
        }

        private readonly TripInformationViewModel _viewModel;
        public TripInformationPage()
        {
            InitializeComponent();
            BindingContext = _viewModel = new TripInformationViewModel();
            _viewModel.BluetoothStatusChanged += _viewModel_BluetoothStatusChanged;
        }

        private void _viewModel_BluetoothStatusChanged()
        {
            BluetoothStatusUpdated?.Invoke();
        }
       
        void OnDuressPressed(object sender, EventArgs args)
        {
            _viewModel.StartDriverDuress();
        }
        void OnDuressReleased(object sender, EventArgs args)
        {
            _viewModel.EndDriverDuress();
        }

        private void BtnPlot_Clicked(object sender, EventArgs e)
        {
            //Navigation.PushAsync(new AvailablePlotTabletPage());
        }
        private void OnMapIconTapped(object sender, EventArgs e)
        {
            var location = new Location(33.8688, 151.2093); // Replace with desired coordinates
            var options = new MapLaunchOptions { Name = "Sydney" }; // Replace with desired location name
            Map.OpenAsync(location, options);
        }
        private async void OnWazeIconTapped(object sender, EventArgs e)
        {
            // if App Url doesnt work use Browser Url => "https://waze.com/ul?q=" + latLng.latitude + "," + latLng.longitude + "&navigate=yes&zoom=17"; 
            //string latitude = "33.8688";
            //string longitude = "151.2093";
            string wazeUri = "waze://";

            try
            {
                // Launch Waze app
                await Launcher.OpenAsync(wazeUri);
            }
            catch (Exception ex)
            {
                string errorMessage = "Waze is not installed in your device, Please install the app first";
                //Navigation.ShowPopup(new ErrorPopup(errorMessage));
            }
        }


    }
}