using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AntdUI;
using DH.Commons.Base;
using DH.Commons.Enums;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Window = AntdUI.Window;

namespace DHSoftware.Views
{
    public partial class CameraControl : UserControl
    {
        Window window;
        CameraBase CameraBase;
        public CameraControl(Window _window, CameraBase cameraBase)
        {
            window = _window;
            CameraBase = cameraBase;
            InitializeComponent();

            sltCamType.TextChanged += SltCamTpye_TextChanged;
            InitData();
            BindData();
        }
        private void SltCamTpye_TextChanged(object? sender, EventArgs e)
        {
            if (sender is Select slt && !string.IsNullOrEmpty(slt.Text))
            {
                // 将文本转换为枚举值
                if (Enum.TryParse<EnumCamType>(slt.Text, out var plcType))
                {
                    switch (plcType)
                    {
                        case EnumCamType.度申Do3think:
                        case EnumCamType.海康hik:
                           
                            break;

                      

                        default:
                            break;
                    }
                }
                else
                {

                }
            }
        }


        private void SltAcquisitionMode_SelectedIndexChanged(object sender, IntEventArgs e)
        {
            switch (e.Value)
            {
                case (int)CameraAcquisitionMode.连续模式:
                    sltTriggerMode.Enabled = false;
                    break;
                case (int)CameraAcquisitionMode.触发模式:
                    sltTriggerMode.Enabled = true;
                    break;
                default:
                    break;
            }
        }


        private void BindData()
        {

            sltCamType.DataBindings.Add("Text", CameraBase, "CamType", true, DataSourceUpdateMode.OnPropertyChanged, "");
            sthPic.DataBindings.Add(nameof(sthPic.Checked), CameraBase, nameof(CameraBase.IsSavePicEnabled),
                true, DataSourceUpdateMode.OnPropertyChanged);
            sthAllPic.DataBindings.Add(nameof(sthAllPic.Checked), CameraBase, nameof(CameraBase.IsAllPicEnabled),
             true, DataSourceUpdateMode.OnPropertyChanged);
            // 启用状态绑定
            swhEnable.DataBindings.Add(nameof(swhEnable.Checked), CameraBase, nameof(CameraBase.IsEnabled),
                true, DataSourceUpdateMode.OnPropertyChanged);

            // 曝光时间绑定(假设iptExposure是NumericUpDown)
            iptExposure.DataBindings.Add(nameof(iptExposure.Value), CameraBase, nameof(CameraBase.Exposure),
                true, DataSourceUpdateMode.OnPropertyChanged, 0M, "N2");

            // 增益绑定
            iptGain.DataBindings.Add(nameof(iptGain.Value), CameraBase, nameof(CameraBase.Gain),
                true, DataSourceUpdateMode.OnPropertyChanged, 0M, "N2");

            // 旋转角度绑定
            iptRevolve.DataBindings.Add(nameof(iptRevolve.Value), CameraBase, nameof(CameraBase.RotateImage),
                true, DataSourceUpdateMode.OnPropertyChanged, 0M, "N2");

            // ROI坐标绑定
            iptROIX.DataBindings.Add(nameof(iptROIX.Value), CameraBase, nameof(CameraBase.ROIX));
            iptROIY.DataBindings.Add(nameof(iptROIY.Value), CameraBase, nameof(CameraBase.ROIY));
            iptROIW.DataBindings.Add(nameof(iptROIW.Value), CameraBase, nameof(CameraBase.ROIW));
            iptROIH.DataBindings.Add(nameof(iptROIH.Value), CameraBase, nameof(CameraBase.ROIH));

            // 采集模式下拉框处理
            sltAcquisitionMode.SelectedIndexChanged += (s, e) =>
            {
                CameraBase.IsContinueMode = sltAcquisitionMode.SelectedIndex == 0;
            };

            // 触发模式下拉框处理
            sltTriggerMode.SelectedIndexChanged += (s, e) =>
            {
                CameraBase.IsHardwareTrigger = sltTriggerMode.SelectedIndex == 1;
            };
        }

        private void InitData()
        {
            // 获取枚举字段名列表(原描述改为字段名)
            sltCamType.Items.Clear();
            foreach (EnumCamType value in Enum.GetValues(typeof(EnumCamType)))
            {
                sltCamType.Items.Add(value.ToString());
            }
            // 初始化下拉框选项
            sltAcquisitionMode.Items.AddRange(new[] { "连续模式", "触发模式" });
            sltTriggerMode.Items.AddRange(new[] { "软触发", "硬触发" });

            // 设置初始选择
            sltAcquisitionMode.SelectedIndex = CameraBase.IsContinueMode ? 0 : 1;
            sltTriggerMode.SelectedIndex = CameraBase.IsHardwareTrigger ? 1 : 0;
        }

    }
}