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

namespace NavisworksTransport.UI.WPF.Views
{
    /// <summary>
    /// TimeTagDialog.xaml 的交互逻辑
    /// 时间标签设置对话框 - 用于路径时间分段计算和标签设置
    /// </summary>
    public partial class TimeTagDialog : Window
    {
        /// <summary>
        /// 初始化时间标签设置对话框
        /// </summary>
        public TimeTagDialog()
        {
            try
            {
                InitializeComponent();
                LogManager.Info("TimeTagDialog初始化完成");
                
                // 设置窗口标题包含当前时间
                Title = $"时间标签设置 [{DateTime.Now:MM-dd HH:mm}]";
                
                // 设置ViewModel
                this.DataContext = new TimeTagViewModel();
                
                LogManager.Info("TimeTagDialog ViewModel设置完成");
            }
            catch (Exception ex)
            {
                LogManager.Error($"初始化TimeTagDialog失败: {ex.Message}", ex);
            }
        }
        
        
        /// <summary>
        /// 关闭按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                LogManager.Info("用户关闭时间标签设置对话框");
                this.Close();
            }
            catch (Exception ex)
            {
                LogManager.Error($"关闭TimeTagDialog时发生错误: {ex.Message}", ex);
            }
        }
        
        /// <summary>
        /// 窗口关闭时的清理工作
        /// </summary>
        /// <param name="e"></param>
        protected override void OnClosed(EventArgs e)
        {
            try
            {
                // 执行清理工作（如果需要）
                LogManager.Info("TimeTagDialog已关闭，执行清理");
                
                base.OnClosed(e);
            }
            catch (Exception ex)
            {
                LogManager.Error($"TimeTagDialog清理过程中发生错误: {ex.Message}", ex);
            }
        }
    }
}