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 AR;
using COMM;

namespace Project.ViewForm
{
    public partial class fFlag : Form
    {
        public fFlag()
        {
            InitializeComponent();

            
            this.FormClosed += FIO_FormClosed;
        }

        private void fFlag_Load(object sender, EventArgs e)
        {
            MakeControl();
            this.timer1.Start();
        }

        void MakeControl()
        {
            ListView[] lvs = new ListView[] { listView1, listView2, listView3, listView4 };
            foreach (var lv in lvs)
            {
                lv.Columns.Clear();
                lv.Columns.Add("Idx");
                lv.Columns.Add("Title");
                lv.Columns.Add("Value");
                lv.Columns[0].Width = 25;
                lv.Columns[1].Width = 150;
                lv.Columns[2].Width = 100;
            }
            Array valuelist;

            valuelist = Enum.GetValues(typeof(COMM.eVarBool));
            foreach (var item in valuelist)
            {
                var v = (COMM.eVarBool)item;
                var lv = listView1.Items.Add($"{(int)v}");
                lv.SubItems.Add($"{item}");
                lv.SubItems.Add("--");
            }

            valuelist = Enum.GetValues(typeof(COMM.eVarInt32));
            foreach (var item in valuelist)
            {
                var v = (COMM.eVarInt32)item;
                var lv = listView2.Items.Add($"{(int)v}");
                lv.SubItems.Add($"{item}");
                lv.SubItems.Add("--");
            }

            valuelist = Enum.GetValues(typeof(COMM.eVarString));
            foreach (var item in valuelist)
            {
                var v = (COMM.eVarString)item;
                var lv = listView3.Items.Add($"{(int)v}");
                lv.SubItems.Add($"{item}");
                lv.SubItems.Add("--");
            }

            valuelist = Enum.GetValues(typeof(COMM.eVarTime));
            foreach (var item in valuelist)
            {
                var v = (COMM.eVarString)item;
                var lv = listView4.Items.Add($"{(int)v}");
                lv.SubItems.Add($"{item}");
                lv.SubItems.Add("--");
            }


        }

        private void FIO_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.timer1.Stop();
        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Stop();
            listView1.SuspendLayout();
            foreach (ListViewItem item in listView1.Items)
            {
                var idx = int.Parse(item.SubItems[0].Text);
                var v = VAR.BOOL.Get(idx);
                var desc = VAR.BOOL.GetCodeDesc(idx);
                item.SubItems[2].Text = v ? "O" : "X";
            }
            listView1.ResumeLayout();
            listView2.SuspendLayout();
            foreach (ListViewItem item in listView2.Items)
            {
                var idx = int.Parse(item.SubItems[0].Text);
                var v = VAR.I32.Get(idx);
                var desc = VAR.I32.GetCodeDesc(idx);
                item.SubItems[2].Text = v.ToString();
            }
            listView2.ResumeLayout();
            listView3.SuspendLayout();
            foreach (ListViewItem item in listView3.Items)
            {
                var idx = int.Parse(item.SubItems[0].Text);
                var v = VAR.STR.Get(idx);
                var desc = VAR.STR.GetCodeDesc(idx);
                item.SubItems[2].Text = v;
            }
            listView3.ResumeLayout();
            listView4.SuspendLayout();
            foreach (ListViewItem item in listView4.Items)
            {
                var idx = int.Parse(item.SubItems[0].Text);
                var v = VAR.TIME.Get(idx);
                var desc = VAR.TIME.GetCodeDesc(idx);
                item.SubItems[2].Text = v.ToString("HH:mm:ss.fff");
            }
            listView4.ResumeLayout();
            timer1.Start();
        }

        private void fFlag_VisibleChanged(object sender, EventArgs e)
        {
            this.timer1.Enabled = this.Visible;
            if (timer1.Enabled) timer1.Start();
            else timer1.Stop();
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
