
using System.Windows;

namespace NavisworksTransport.UI.WPF.Views
{
    /// <summary>
    /// 吊装提升高度设置对话框
    /// </summary>
    public partial class AerialHeightDialog : Window
    {
        /// <summary>
        /// 获取或设置提升高度（米）
        /// </summary>
        public double LiftHeightMeters { get; private set; }

        /// <summary>
        /// 获取是否设为终点（完成路径）
        /// </summary>
        public bool IsSetAsEndPoint { get; private set; }

        /// <summary>
        /// 获取是否2点路径模式（仅起点→终点，无下降段）
        /// </summary>
        public bool IsTwoPointMode { get; private set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public AerialHeightDialog()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 构造函数（带默认值）
        /// </summary>
        /// <param name="defaultHeight">默认高度（米）</param>
        public AerialHeightDialog(double defaultHeight) : this()
        {
            HeightTextBox.Text = defaultHeight.ToString("F1");
        }

        /// <summary>
        /// 确定按钮点击事件 - 添加层级（继续）
        /// </summary>
        private void OnOKClick(object sender, RoutedEventArgs e)
        {
            if (ValidateHeight())
            {
                IsSetAsEndPoint = false;
                DialogResult = true;
            }
        }

        /// <summary>
        /// 设为终点按钮点击事件 - 完成路径
        /// </summary>
        private void OnSetAsEndPointClick(object sender, RoutedEventArgs e)
        {
            if (ValidateHeight())
            {
                IsSetAsEndPoint = true;
                DialogResult = true;
            }
        }

        /// <summary>
        /// 2点路径按钮点击事件 - 仅起点到终点的垂直路径
        /// </summary>
        private void OnTwoPointPathClick(object sender, RoutedEventArgs e)
        {
            if (ValidateHeight())
            {
                IsTwoPointMode = true;
                DialogResult = true;
            }
        }

        /// <summary>
        /// 取消按钮点击事件
        /// </summary>
        private void OnCancelClick(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }

        /// <summary>
        /// 验证输入的高度是否有效
        /// </summary>
        private bool ValidateHeight()
        {
            if (double.TryParse(HeightTextBox.Text, out double height) && height > 0)
            {
                LiftHeightMeters = height;
                return true;
            }
            else
            {
                System.Windows.MessageBox.Show("请输入有效的提升高度（大于0的数字）", "错误",
                    MessageBoxButton.OK, MessageBoxImage.Error);
                return false;
            }
        }
    }
}