using GalaSoft.MvvmLight.Messaging;
using MaterialDesignThemes.Wpf;
using MWS.ILayer.Base;
using MWSDomain.Common.UserControls;
using MWSDomain.Common.UserControls.Common;
using MWSDomain.SysModule;
using System;
using System.Threading.Tasks;
using System.Windows;

namespace MWSDomain.ViewDialog.Step
{
    /// <summary>
    /// 消息处理-HOST
    /// </summary>
    public class MsgHostBoxViewDlg : BaseViewDialog<MsgHostBox>, IModelDialog
    {
    }

    /// <summary>
    /// 消息处理-Window
    /// </summary>
    public class MsgBoxViewDlg : BaseViewDialog<MsgBox>, IModelDialog
    {

        public override void BindViewModel<TViewModel>(TViewModel viewModel)
        {
            GetDialogWindow().DataContext = viewModel;
        }

        public override Task<bool> ShowDialog(DialogOpenedEventHandler openedEventHandler = null, DialogClosingEventHandler closingEventHandler = null)
        {
            var dialog = GetDialogWindow();
            dialog.ShowDialog();
            return Task.FromResult((dialog.DataContext as BaseDialogOperation).Result);
        }

        public override void RegisterDefaultEvent()
        {
            Messenger.Default.Register<string>(GetDialogWindow(), "DialogClose", new Action<string>((msg) =>
            {
                GetDialogWindow().Close();
            }));

        }

        private Window GetDialogWindow()
        {
            return GetDialog() as Window;
        }
    }
}
