﻿
namespace SBVaccine.ViewModels.Controls
{
    using Vaccine.Data.Models;
    using System.Windows.Input;
    using SBVaccine.Models.Providers;
    using SBVaccine.ViewModels.Commands;
    using SBVaccine.Presentation.Models.Providers;

    public class PersonsControllerViewModel : BaseViewModel
    {
        //private BaseViewModel previewItem;

        private BaseViewModel selectedItem;
        public BaseViewModel SelectedItem
        {
            get
            {
                return selectedItem;
            }
            set
            {
                selectedItem = value;
                OnPropertyChanged();
            }
        }

        public PersonsControllerViewModel()
        {
            if (SelectedItem == null)
            {
                SelectedItem = ViewModelContainer<PersonNavigatorViewModel>.Get();
            }
        }

        #region Commands
        private RelayCommand setPersonEditor;
        public ICommand SetPersonEditor
        {
            get
            {
                return setPersonEditor ??
                (setPersonEditor = new RelayCommand(obj =>
                {
                    SelectedItem = ViewModelContainer<PersonEditorViewModel>.Get();
                    if (obj is Person person)
                    {
                        (selectedItem as PersonEditorViewModel).PersonData = person;
                        PersonStoryProvider.Add(person);
                    }
                    else
                    {
                        (selectedItem as PersonEditorViewModel).PersonData = new Person();
                    }
                }));
            }
        }

        private RelayCommand setPersonLayout;
        public ICommand SetPersonLayout
        {
            get
            {
                return setPersonLayout ??
                (setPersonLayout = new RelayCommand(obj =>
                {
                    if (obj is Person person)
                    {
                        SelectedItem = ViewModelContainer<PersonLayoutViewModel>.Get();
                        (SelectedItem as PersonLayoutViewModel).PersonData = person;
                        PersonStoryProvider.Add(person);
                    }
                    else
                    {
                        //todo error
                    }
                }));
            }
        }

        private RelayCommand setPersonNavigator;
        public ICommand SetPersonNavigator
        {
            get
            {
                return setPersonNavigator ??
                (setPersonNavigator = new RelayCommand(obj =>
                {
                    if (obj is string usercontroler)
                    {
                    }
                    SelectedItem = ViewModelContainer<PersonNavigatorViewModel>.Get(); ;
                }));
            }
        }

        private RelayCommand setBackView;
        public ICommand SetBackView
        {
            get
            {
                return setBackView ??
                (setBackView = new RelayCommand(obj =>
                {
                    if (obj is string usercontroler)
                    {
                        //todo
                    }
                    SelectedItem = ViewModelContainer.GetBack();
                }));
            }
        }
        #endregion
    }
}
