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 Hawkeye.VisionBuilder.Workflow;

namespace Hawkeye.VisionBuilder.Features.Yolo
{
    public partial class AttributeSetter : Form
    {
        private readonly WorkflowList _list;

        public AttributeSetter(WorkflowList list)
        {
            _list = list;
            InitializeComponent();
        }

        void TrySet(TextBox textBox, Action<int> setter)
        {
            if (int.TryParse(textBox.Text, out var v))
            {
                setter(v);
            }
        }


        private void button1_Click(object sender, EventArgs e)
        {
            foreach (var operation in _list.Operations)
            {
                if (operation is Hawkeye.VisionBuilder.Workflow.Operations.AI.YoloPickDetected yolo)
                {
                    TrySet(tbMinWidth, v => yolo.MinWidth = v);
                    TrySet(tbMinHeight, v => yolo.MinHeight = v);
                    TrySet(tbMaxWidth, v => yolo.MaxWidth = v);
                    TrySet(tbMaxHeight, v => yolo.MaxHeight = v);
                    TrySet(tbMinArea, v => yolo.MinArea = v);
                    TrySet(tbMaxArea, v => yolo.MaxArea = v);
                }
            }
            DialogResult = DialogResult.OK;
        }
    }
}
