using Ramitta;
using static Ramitta.lib.Basic;

using Newtonsoft.Json.Linq;
using System.Diagnostics;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace template
{
    public partial class MainWindow : Window
    {
        static string? filePath;
        private JToken? _currentJsonData = null;
        private string? _currentFilePath = null;

        #region 初始化MainWindow
        public MainWindow(StartupEventArgs e)
        {
            Startupe = ParseCommandLineArgs(e.Args);
            InitializeComponent();
            if (Startupe.TryGetValue("getfile", out string filePath))
            {
                MainWindow.filePath = filePath;
                DebugBar(Debugtag, $"操作目标:{filePath}", 正常绿色);

            }
            else
            {
                DebugBar(Debugtag, $"未指定操作目标", 警告橙色);
            }
        }
        #endregion


        private void 增(object sender, RoutedEventArgs e)
        {
            var stable = TreeList.AddLabelNode("GROUP");
            TreeList.AddCheckboxNode("A");
            TreeList.AddCheckboxNode("B", parent: stable);
            TreeList.AddCheckboxNode("C");

            _ = Dispatcher.BeginInvoke(new Action(() =>
            {
                TreeList.Find<CheckboxTreeNode, CheckBox>(null, "A");
                TreeList.Find<CheckboxTreeNode, CheckBox>(null, "B");
                TreeList.Find<CheckboxTreeNode, CheckBox>(null, "C");
            }), DispatcherPriority.Loaded);
        }

        private void 改(object sender, RoutedEventArgs e)
        {

        }

        private void 删(object sender, RoutedEventArgs e)
        {

        }

        private void 查(object sender, RoutedEventArgs e)
        {

            List<TreeNode> val = TreeList.FindAllTreeNodes(TreeList.Nodes, "A", typeof(LabelTreeNode));

            if (val.Count > 0)
            {
                DebugBar(Debugtag, $"{val.Count} 信息: {val[0].Text}", 默认灰色);
            }
            else
            {
                DebugBar(Debugtag, "没有找到任何相关信息", 正常绿色);
            }
        }
    }
}