using System;
using System.Windows.Controls;
using NavisworksTransport.UI.WPF.ViewModels;

namespace NavisworksTransport.UI.WPF.Views
{
    /// <summary>
    /// ModelSettingsView.xaml 的交互逻辑 - 使用新的ModelSettingsViewModel
    /// </summary>
    public partial class ModelSettingsView : UserControl
    {
        public ModelSettingsView(LogisticsControlViewModel mainViewModel = null)
        {
            InitializeComponent();
            
            try
            {
                // 设置数据上下文为新的ViewModel，传入主ViewModel引用
                DataContext = new ModelSettingsViewModel(mainViewModel);
                LogManager.Info("ModelSettingsView已初始化，使用新的ModelSettingsViewModel");
            }
            catch (System.Exception ex)
            {
                LogManager.Error($"ModelSettingsView初始化失败: {ex.Message}", ex);
            }
        }

        /// <summary>
        /// 清理资源
        /// </summary>
        public void Cleanup()
        {
            try
            {
                // 清理ViewModel
                if (DataContext is ModelSettingsViewModel viewModel)
                {
                    viewModel.Dispose();
                    LogManager.Info("ModelSettingsView资源清理完成");
                }
            }
            catch (Exception ex)
            {
                LogManager.Error($"ModelSettingsView清理失败: {ex.Message}");
            }
        }
    }
}