﻿using ProjectManagement.ViewModels;
using System;
using System.Windows;
using System.Windows.Data;

namespace ProjectManagement.Converters
{
    public class StringToViewModelConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var viewModel = value as string;
            var mainWindow = Application.Current.MainWindow as Window;

            switch (viewModel)
            {
                case "LogInViewModel":
                    mainWindow.WindowState = WindowState.Normal;
                    mainWindow.ResizeMode = ResizeMode.NoResize;
                    mainWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                    mainWindow.MinWidth = 0;
                    mainWindow.MinHeight = 0;
                    mainWindow.Height = 350;
                    mainWindow.Width = 525;

                    var logInViewModel = (Application.Current.MainWindow.DataContext as MainViewModel).LogInViewModel;
                    logInViewModel.UserName = null;

                    return logInViewModel;
                case "ProjectViewModel":
                    mainWindow.ResizeMode = ResizeMode.CanResize;
                    mainWindow.WindowState = WindowState.Maximized;
                    mainWindow.MinWidth = 500;
                    mainWindow.MinHeight = 500;

                    return (mainWindow.DataContext as MainViewModel).ProjectViewModel;
            }

            return viewModel;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
