using DevExpress.XtraEditors;
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 LFP_Manager.DataStructure;

namespace LFP_Manager.Forms
{
    public partial class fmxModuleDetail : DevExpress.XtraEditors.XtraForm
    {
        #region VARIABLES
        private int ModuleID = 1;
        private CommConfig Config;
        private CsDeviceData.DeviceModuleData[] ModuleDatas;

        #endregion

        #region COSTRUCTORS

        public fmxModuleDetail(int mID, ref CommConfig aConfig, ref CsDeviceData.DeviceModuleData[] mData)
        {
            InitializeComponent();

            ModuleID = mID;
            Config = aConfig;
            ModuleDatas = mData;

            this.Text = String.Format("MODULE [#{0:00}]"
                , mID
                );
            ShelfStatus.Start(mID, ref aConfig, ref ModuleDatas);
        }

        #endregion

        #region PUBLIC FUNCTION

        public void SetModuleID(int mID)
        {
            ShelfStatus.ModuleIDSet(mID);

            if (this.InvokeRequired)
            {
                this.Invoke(new MethodInvoker(delegate ()
                {
                    this.Text = String.Format("MODULE [#{0:00}]", mID);
                }));
            }
            else
            {
                this.Text = String.Format("MODULE [#{0:00}]", mID);
            }
        }

        public int GetModuleID()
        {
            return ShelfStatus.ModuleIDGet();
        }
        #endregion

        #region UPDATE DATA

        public void UpdateData(ref CsDeviceData.DeviceModuleData[] mData)
        {
            ShelfStatus.UpdateData(mData);
        }

        #endregion

        #region BUTTON EVENT
        private void btnPrev_Click(object sender, EventArgs e)
        {
            if (ModuleID == 1)
            {
                ModuleID = Config.ModuleQty;
            }
            else
            {
                ModuleID--;
            }
            ShelfStatus.ModuleIDSet(ModuleID);
            ShelfStatus.UpdateData(ModuleDatas);
            Text = string.Format("Module Status [#{0:00}]", ModuleID);
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (ModuleID == Config.ModuleQty)
            {
                ModuleID = 1;
            }
            else
            {
                ModuleID++;
            }
            ShelfStatus.ModuleIDSet(ModuleID);
            ShelfStatus.UpdateData(ModuleDatas);
            Text = string.Format("Module Status [#{0:00}]", ModuleID);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }
        #endregion
    }
}