using System.Reflection;
using System.Windows;

namespace BPA.SingleDevice.ViewModel
{
    public class MainViewModel : NotifyBase
    {
        public MainViewModel()
        {
            ViewItems = new ObservableCollection<ViewItem>
            {
                new ViewItem("点单主页",  new OrderMainView(), IconType.Home3Fill),
                new ViewItem("配方管理",  new RecipeManagementView(), IconType.NewspaperFill),
                //new ViewItem("原料管理", new RawMaterialManagementView(), IconType.ReservedFill),
                new ViewItem("设备物料绑定", new MaterialBindingView(), IconType.ReservedFill),

                new ViewItem("物料管理", new MaterialManagementView(), IconType.BookLine),
                new ViewItem("运行日志",new RunLogView(),IconType.FileTextLine),
                new ViewItem("操作日志",new UserLogView(),IconType.AccountPinCircleLine),
                //new ViewItem("报警日志",new AlarmLogView(),IconType.AlarmWarningLine),
                new ViewItem("调试日志",new DebugLogView(),IconType.BugLine),
                new ViewItem("配方完成日志",new RecipeCompletView(),IconType.TaskLine),
                new ViewItem("变量监控",new VarMonitorView(),IconType.Dashboard3Line),
                //new ViewItem("参数设置",new ParamsSetView(),IconType.Settings4Line),
                new ViewItem("调试设置",new DebugView(),IconType.Settings4Line),

                new ViewItem("配方执行状态",new RecipeStatusView(),IconType.ListRadio)
            };

            SelecteCommand = new BPARelayCommand<object>(DoNavChanged);
        }

        public ObservableCollection<ViewItem> ViewItems { get; set; } = new ObservableCollection<ViewItem>();

        public BPARelayCommand<object> SelecteCommand { get; set; }

        public ViewItem CurrentViewItem
        {
            get { return _mCurrentViewItem; }
            set
            {
                _mCurrentViewItem = value;
                OnPropertyChanged();
                var res = ViewItems.FirstOrDefault(p => p.Name == value.Name);
                res.Content = Activator.CreateInstance(res.Content.GetType());
            }
        }

        private ViewItem _mCurrentViewItem = new ViewItem();

        private void DoNavChanged(object obj)
        {
            if (obj != null)
            {
                Type type = Type.GetType($"BPA.SingleDevice.View.{obj.ToString()}");
                ConstructorInfo cti = type?.GetConstructor(Type.EmptyTypes);
                MainContent = (FrameworkElement)cti?.Invoke(null);
            }
        }

        public FrameworkElement MainContent
        { get { return _mMainContent; } set { _mMainContent = value; OnPropertyChanged(); } }
        private FrameworkElement _mMainContent;
    }
}