using CommunityToolkit.Mvvm.Input;
using FLY.Thick.Base.UI.OnInit;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows;

namespace FLY.Thick.Base.UI
{
    /// <summary>
    /// WdSkipWarningUnityNames.xaml 的交互逻辑
    /// </summary>
    public partial class WdWarningUnityNames : FLY.ControlLibrary.WindowBigClose
    {
        WdWarningUnityNamesVm viewModel;
        public WdWarningUnityNames()
        {
            InitializeComponent();
        }
        public void Init(WarningSystemManager warningSystemManager)
        {
            viewModel = new WdWarningUnityNamesVm();
            viewModel.Init(warningSystemManager);
            this.DataContext = viewModel;
        }

    }
    public class WdWarningUnityNamesVm : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public ObservableCollection<WarningName> WarningNames { get; } = new ObservableCollection<WarningName>();
        public RelayCommand OkCmd { get; private set; }

        WarningSystemManager warningSystemManager;
        public WdWarningUnityNamesVm()
        {
            OkCmd = new RelayCommand(Ok);
        }



        public void Init(WarningSystemManager warningSystemManager)
        {
            this.warningSystemManager = warningSystemManager;
            var names = warningSystemManager.GetWarningNames();
            foreach (var name in names)
                WarningNames.Add(name);
        }

        private void Ok()
        {
            var skips = WarningNames.Where(w => !w.IsRegistered).Select(w => w.UnityName).ToList();
            warningSystemManager.SetSkipWarningName(skips);

            string tit = (string)Application.Current.TryFindResource("str.PgErrorTable.OperateSuccessfully");
            FLY.ControlLibrary.Window_Tip.Show(tit,null,TimeSpan.FromSeconds(2));
        }
    }
    public class WdWarningUnityNamesVmUt : WdWarningUnityNamesVm
    {
        public WdWarningUnityNamesVmUt()
        {
            WarningNames.Add(new WarningName() { UnityName = "测厚仪" });
            WarningNames.Add(new WarningName() { UnityName = "风环" });
            WarningNames.Add(new WarningName() { UnityName = "称重", IsRegistered = false });


        }
    }
}
