using AGVControl.Models;
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;

namespace AGVControl.Dialog
{
    public partial class fPropertyRFIDPoint : Form
    {
        RFIDPoint RFIDPt;
        List<RFIDConnection> Connections;
        public fPropertyRFIDPoint(RFIDPoint point, List<RFIDConnection> connection)
        {
            InitializeComponent();
            this.RFIDPt = point;
            this.Connections = connection;
            this.propertyGrid1.SelectedObject = point;
            this.KeyPreview = true;
            this.KeyDown += (s1, e1) => {
                if (e1.KeyCode == Keys.Escape) this.Close();
            };
        }

        private void fPropertyRFIDPoint_Load(object sender, EventArgs e)
        {
            foreach (var item in Connections)
                comboBox1.Items.Add($"{item.P1.Value} ↔ {item.P2.Value}");

            if(comboBox1.Items.Count > 0)
            comboBox1.SelectedIndex = 0;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.propertyGrid2.SelectedObject = this.Connections[this.comboBox1.SelectedIndex];
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var item = this.Connections[this.comboBox1.SelectedIndex];
            var p1 = item.P1;
            var p2 = item.P2;
            item.P2 = p1;// item.P1;
            item.P1 = p2;// p1;
            this.propertyGrid2.SelectedObject = item;
            this.Validate();
        }
    }
}
