using Dropbox.Api.FileProperties;
using PDF_Office.EventAggregators;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace PDF_Office.ViewModels.EditTools.Background
{
    public class BackgroundTemplateListBaseContentViewModel : BindableBase, INavigationAware
    {
        public IRegionManager backgroundTemplateListRegion;
        private readonly IEventAggregator eventAggregator;

        private string _currentTemplateListName;
        public string CurrentTemplateListName
        {
            get { return _currentTemplateListName; }
            set { _currentTemplateListName = value; }
        }

        private string backgroundTemplateListRegionName;

        public string BackgroundTemplateListRegionName
        {
            get => backgroundTemplateListRegionName;
            set => SetProperty(ref backgroundTemplateListRegionName, value);
        }


        private System.Windows.Visibility backgroundTemplateListVisible;
        public System.Windows.Visibility BackgroundTemplateListVisible
        {
            get => backgroundTemplateListVisible;
            set => SetProperty(ref backgroundTemplateListVisible, value);
        }

        public DelegateCommand<object> ChangeTemplateListModCommand { get; set; }
        public DelegateCommand EnterCreateCommand { get; set; }

        public BackgroundTemplateListBaseContentViewModel(IRegionManager backgroundTemplateListRegion, IEventAggregator eventAggregator)
        {
            this.backgroundTemplateListRegion = backgroundTemplateListRegion;
            this.eventAggregator = eventAggregator;
            BackgroundTemplateListRegionName = Guid.NewGuid().ToString();
            ChangeTemplateListModCommand = new DelegateCommand<object>(ChangeTemplateListMod);
            EnterCreateCommand = new DelegateCommand(EnterCreate);
            EnterSelectedTemplateListMod("BackgroundTemplateListColorContent");
        }

        public void EnterCreate()
        {
            this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(EnumTemplateListOrCreate.StatusCreate);
        }

        public void EnterSelectedTemplateListMod(string currentTemplateListName)
        {
            backgroundTemplateListRegion.RequestNavigate(BackgroundTemplateListRegionName, currentTemplateListName);
            backgroundTemplateListVisible = System.Windows.Visibility.Visible;
        }

        public void ChangeTemplateListMod(object e)
        {
            var args = e as Button;
            if (args != null)
            {
                CurrentTemplateListName = args.Name;
                EnterSelectedTemplateListMod(CurrentTemplateListName);
            }
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
        }
    }
}