using System;
using System.Windows;

namespace NavisworksTransport.UI.WPF.Views
{
    /// <summary>
    /// 坐标系检测结果对话框 - 支持文本选择和复制
    /// </summary>
    public partial class CoordinateSystemResultDialog : Window
    {
        public CoordinateSystemResultDialog()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 设置要显示的结果文本
        /// </summary>
        public string ResultText
        {
            get => ResultTextBox.Text;
            set => ResultTextBox.Text = value;
        }

        /// <summary>
        /// 复制按钮点击事件
        /// </summary>
        private void CopyButton_Click(object sender, RoutedEventArgs e)
        {
            if (ClipboardHelper.TrySetText(ResultTextBox.Text, "捕获真实物体位姿"))
            {
                return;
            }

            MessageBox.Show("复制到剪贴板失败，请稍后重试。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
        }

        /// <summary>
        /// 确定按钮点击事件
        /// </summary>
        private void OkButton_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
            Close();
        }

        /// <summary>
        /// 静态方法，方便调用显示结果
        /// </summary>
        public static void ShowResult(string title, string content, Window owner = null)
        {
            var dialog = new CoordinateSystemResultDialog
            {
                Title = title,
                ResultText = content
            };

            if (owner != null)
            {
                dialog.Owner = owner;
            }
            else
            {
                // 尝试设置当前活动窗口为所有者
                try
                {
                    dialog.Owner = System.Windows.Application.Current?.MainWindow;
                }
                catch (Exception ex)
                {
                    LogManager.Debug($"[坐标系对话框] 设置Owner失败: {ex.Message}");
                }
            }

            dialog.ShowDialog();
        }
    }
}
