using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using XKRS.Common.Interface;
using XKRS.Common.Model.Helper;

namespace XKRS.UI.Model.Winform
{
    public partial class MenuFormBase : DockContent
    {
        public Action<string,IProcess> OnUploadProcess { get; set; }
        public event Action<LogMsg> OnLogMsgOutput;
        public event Action<bool> OnShowWaitingBar;
        public event Action<bool> OnIsLoginChanged;

        public string Id { get; set; } = Guid.NewGuid().ToString();

        private IProcess process = null;
        public IProcess Process
        {
            get => process;
            set
            {
                if (process != value)
                {
                    process = value;
                    OnProcessUpdated();
                }
            }
        }

        public MenuFormBase()
        {
            InitializeComponent();
            KeyPreview = true;
            var dockAttr = GetType().GetCustomAttribute<DockOptionAttribute>();
            if (dockAttr != null)
            {
                FormClosing += MenuFormBase_FormClosing;
            }
        }

        private void MenuFormBase_FormClosing(object sender, FormClosingEventArgs e)
        {
            throw new NotImplementedException();
        }

        #region IProcessObserver
        public virtual void OnProcessUpdated() { }

        public virtual void DownloadProcess(IProcess process)
        {
           Process = process;
        }

        #endregion

        #region ILogOutput
        public virtual void LogDisplay(LogMsg msg) { }

        #endregion



        #region Login
        protected virtual bool IsLogin { get; set; }
        public virtual void SetLoginStatus(bool isLogin)
        {
            IsLogin = isLogin;
            OnIsLoginChanged?.Invoke(IsLogin);
        }
        #endregion


    }
}
