using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using StartServerWPF.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Principal;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Unicode;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace StartServerWPF.Modules.MseedChart.ViewModels
{
    public class ChartStationDialogViewModel : BindableBase, IDialogAware
    {
        public ChartStationDialogViewModel(WorkareaModel workareaModel)
        {
            this._workareaModel = workareaModel;
        }
        private string _title = "台站选择";
        public string Title => _title;
        private ObservableCollection<StationState> _stationsSource;
        public ObservableCollection<StationState> StationsSource
        {
            get => _stationsSource;
            set { SetProperty(ref _stationsSource, value); }
        }

        public event Action<IDialogResult> RequestClose;

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
            //  _title = "编辑" + _title;
            var stations = parameters.GetValue<List<StationState>>("station");
            StationsSource = new ObservableCollection<StationState>();
            stations.ForEach(s => { StationsSource.Add(s); });
        }

        private VpnInfo _mainModel = new VpnInfo();
        public VpnInfo MainModel
        {
            get => _mainModel;
            set { SetProperty(ref _mainModel, value); }
        }
        private DateTime _moniTime ;
        private readonly WorkareaModel _workareaModel;

        public DateTime MoniTime
        {
            get => _moniTime;
            set { SetProperty(ref _moniTime, value); }
        }
        public DelegateCommand SureCommand => new DelegateCommand(() => 
        {
            CloseDialog(new DialogResult(ButtonResult.OK));

        });
        public  void CloseDialog(DialogResult dialogResult)
        {
            List<StationState> stations = new List<StationState>();
            foreach (var item in StationsSource)
            {
                stations.Add(item);
            }
            dialogResult.Parameters.Add("station",stations);
            RequestClose?.Invoke(dialogResult);
        }
        public ICommand CancelCommand
        {
            get => new DelegateCommand(() =>
            {
                RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
            });
        }

        private string isLoadingVisibile = "Hidden";

        public string IsLoadingVisibile
        {
            get { return isLoadingVisibile; }
            set { SetProperty(ref isLoadingVisibile, value); }
        }

        private string _loadingMessage;

        public string LoadingMessage
        {
            get { return _loadingMessage; }
            set { SetProperty(ref _loadingMessage, value); }
        }

    }
}
