using Microsoft.Maui.ApplicationModel;
using Microsoft.Maui.Controls;
using QSF.Common;
using System.Windows.Input;
using TelerikMauiApp2;

namespace QSF.ViewModels;

public abstract class PageViewModel : ViewModelBase
{
    private static BrowserLaunchOptions browserLaunchOptions;

    private string appTitle;
    private string headerTitle;
    private string headerDescription;
    private string headerIcon;
   

    public PageViewModel()
    {
        browserLaunchOptions = new BrowserLaunchOptions()
        {
            TitleMode = BrowserTitleMode.Show,
            PreferredControlColor = Microsoft.Maui.Graphics.Colors.White,
            PreferredToolbarColor = Microsoft.Maui.Graphics.Colors.AliceBlue
        };

 
    }

    public string AppTitle
    {
        get
        {
            return this.appTitle;
        }
        protected set
        {
            this.UpdateValue(ref this.appTitle, value);
        }
    }

    public string HeaderTitle
    {
        get
        {
            return this.headerTitle;
        }
        set
        {
            this.UpdateValue(ref this.headerTitle, value);
        }
    }

    public string HeaderDescription
    {
        get
        {
            return this.headerDescription;
        }
        protected set
        {
            this.UpdateValue(ref this.headerDescription, value);
        }
    }

    public string HeaderIcon
    {
        get
        {
            return this.headerIcon;
        }
        protected set
        {
            this.UpdateValue(ref this.headerIcon, value);
        }
    }

 

    public ICommand NavigateToDocumentationCommand { get; private set; }

    public ICommand NavigateToFeedbackPortalCommand { get; private set; }

    public ICommand NavigateToDownloadTrialCommand { get; private set; }

    public ICommand NavigateToExampleCodeCommand { get; private set; }

    public ICommand NavigateToDescriptionCommand { get; private set; }

    public static void TryNavigateToUrl(string url)
    {
        if (url == null)
        {
            return;
        }

        Browser.Default.OpenAsync(new System.Uri(url), browserLaunchOptions);
    }

    public static void TryNavigateToUrl(string url, ICommand fallbackCommand)
    {
        if (!string.IsNullOrEmpty(url))
        {
            TryNavigateToUrl(url);
        }
        else
        {
            fallbackCommand?.Execute(null);
        }
    }
     
}
