using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Permission;
public class MyUiNumberInput :MyUiInput,IWithMinMaxValue
{
    [Category("MyControl")]
    [Description("允许输入的最小值")]
    public new double Minimum { get => base.Minimum; set { base.Minimum = value; } }

    [Category("MyControl")]
    [Description("允许输入的最大值")]
    public new double Maximum { get => base.Maximum; set => base.Maximum = value; }

    [Category("MyControl")]
    [Description("限值变化时")]
    public event MinMaxValueChanged MinMaxValueChanged;

    [Category("MyControl")]
    [Description("输入的数据类型")]
    //[DefaultValue(UIEditType.Integer)]
    public new UIEditType Type { get=> type; set { base.Type = value; type = value; } }
    private UIEditType type=UIEditType.Integer;

    public MyUiNumberInput() 
    {

    }

    protected override void OnCunstomClick(EventArgs e)
    {
        // 执行软键盘逻辑（由子类或当前类决定）
        if (UseSoftKeyboard)
        {
            ShowSoftKeyboard();
        }
    }

    protected virtual void OnMinMaxValueChanged(double minimum, double maximum)
    {
        MinMaxValueChanged?.Invoke(this, minimum, maximum);
    }
    protected virtual void ShowSoftKeyboard()
    {
        if (this.Type == UIEditType.Integer)
        {
            var kb = new NumberKeybordForm((int)Maximum, (int)Minimum, IntValue);
            var dr = kb.ShowDialog();
            if (dr == DialogResult.OK)
            {
                if (kb.LimitChanged)
                {
                    this.Minimum = kb.Minimum;
                    this.Maximum = kb.Maximum;
                    OnMinMaxValueChanged(kb.Minimum, kb.Maximum);

                }
                if (kb.ValueChanged)
                {
                    IntValue = Convert.ToInt32(kb.Value);
                }

            }
        }
        else if (this.Type == UIEditType.Double)
        {
            var kb = new NumberKeybordForm(Maximum, Minimum, DoubleValue);
            var dr = kb.ShowDialog();
            if (dr == DialogResult.OK)
            {
                if (kb.LimitChanged)
                {
                    this.Minimum = kb.Minimum;
                    this.Maximum = kb.Maximum;
                    OnMinMaxValueChanged(kb.Minimum, kb.Maximum);
                }

                if (kb.ValueChanged)
                {
                    DoubleValue = Convert.ToDouble(kb.Value);
                }

            }
        }
    }
}

