using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using Prism.Commands;

namespace SASDesktop
{
    /// <summary>
    /// Управляет навигацией приложения
    /// </summary>
    class Navigation
    {
        #region Команды
        public static DelegateCommand ToDriverCreate    { get; set; }   = new DelegateCommand(ToDriverCreateExecuted);
        public static DelegateCommand ToDriverList      { get; set; }   = new DelegateCommand(ToDriverListExecuted);

        public static DelegateCommand ToTransportCreate { get; set; }   = new DelegateCommand(ToTransportCreateExecuted);
        public static DelegateCommand ToTransportList   { get; set; }   = new DelegateCommand(ToTransportListExecuted);

        public static DelegateCommand ToLicenseCreate   { get; set; }   = new DelegateCommand(ToLicenseCreateExecuted);
        public static DelegateCommand ToLicenseRemove   { get; set; }   = new DelegateCommand(ToLicenseRemoveExecuted);
        public static DelegateCommand ToLicenseList     { get; set; }   = new DelegateCommand(ToLicenseListExecuted);

        public static DelegateCommand ToTransportAssign { get; set; }   = new DelegateCommand(ToTransportAssignExecuted);

        public static DelegateCommand Logout            { get; set; }   = new DelegateCommand(LogoutExecuted);
        public static DelegateCommand GoBackCmd         { get; set; }   = new DelegateCommand(GoBack);
        #endregion

        /// <summary>
        /// Возвращает главный фрейм приложения
        /// </summary>
        private static Frame GetMainFrame()
        {
            return (App.Current.MainWindow as MainWindow).ContentBody;
        }

        public static void GoBack()
        {
            GetMainFrame().GoBack();
        }
        
        /// <summary>
        /// Показывает кнопку выхода
        /// </summary>
        public static void ShowLogoutButton()
        {
            (App.Current.MainWindow as MainWindow).LogoutButton.Visibility = System.Windows.Visibility.Visible;
        }

        /// <summary>
        /// Скрывает кнопку выхода
        /// </summary>
        public static void HideLogoutButton()
        {
            (App.Current.MainWindow as MainWindow).LogoutButton.Visibility = System.Windows.Visibility.Hidden;
        }

        /// <summary>
        /// Переводит на главную страницу приложения
        /// </summary>
        public static void ToPortal()
        {
            GetMainFrame().Navigate(new Views.Portal());
        }
        
        /// <summary>
        /// Переводит на страницу создания водителя
        /// </summary>
        public static void ToDriverCreateExecuted()
        {
            GetMainFrame().Navigate(new Views.Drivers.Create());
        }
        
        /// <summary>
        /// Переводит на страницу просмотра водителей
        /// </summary>
        public static void ToDriverListExecuted()
        {
            GetMainFrame().Navigate(new Views.Drivers.DriverListOutput());
        }
        
        /// <summary>
        /// Переводит на страницу создания транспорта
        /// </summary>
        public static void ToTransportCreateExecuted()
        {
            GetMainFrame().Navigate(new Views.Transport.Create());
        }
        
        /// <summary>
        /// Переводит на страницу просмотра всех транспортов
        /// </summary>
        public static void ToTransportListExecuted()
        {
            GetMainFrame().Navigate(new Views.Transport.List());
        }

        /// <summary>
        /// Выполняет выход из приложенияя
        /// </summary>
        public static void LogoutExecuted()
        {
            AuthState.CurrentUser = null;
            AuthState.LogoutButtonVisible = false;
            HideLogoutButton();
            GetMainFrame().Navigate(new Views.Auth());
        }
        
        public static void ToLicenseCreateExecuted()
        {
            GetMainFrame().Navigate(new Views.Managment.GivePassCitizen());
        }
        
        public static void ToLicenseRemoveExecuted()
        {
            GetMainFrame().Navigate(new Views.Managment.WithDrowPassCitizen());
        }
        
        public static void ToLicenseListExecuted()
        {
            GetMainFrame().Navigate(new Views.Managment.CitizenPassListOut());
        }
        
        public static void ToTransportAssignExecuted()
        {
            GetMainFrame().Navigate(new Views.Management.Assign());
        }
    }
}
