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;
using LFP_Manager.Function;
using LFP_Manager.Controls;

namespace LFP_Manager.Forms
{
    public partial class fmxEtcStatus : DevExpress.XtraEditors.XtraForm
    {
        public delegate void UpdateEvent(object sendor);
        public delegate void CmdEvent(int sId, int mode, int index, int flag, ref DeviceParamData aParam, ref DeviceCalibration aCalib);

        #region VARIABLES

        int SystemId = 0;
        DeviceSystemData SystemData;
        DeviceParamData Param;
        DeviceCalibration Calib;

        public event UpdateEvent OnUpdate = null;
        public event CmdEvent OnCommand = null;

        #endregion

        #region CONSTRUCTORS

        public fmxEtcStatus()
        {
            InitializeComponent();
        }

        public fmxEtcStatus(int sId, DeviceCalibration aCalib)
        {
            InitializeComponent();

            InitComponent();

            SystemId = sId;
            Calib = aCalib;

            tmrDisplay.Enabled = true;
        }

        public void InitComponent()
        {
            EtcStatusView.OnCommand += OnCmdEvent;
        }

        #endregion

        #region BUTTON EVENT

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

        #endregion

        #region COMMAND EVENT

        private void OnCmdEvent(int mode, int index, int flag, ref DeviceParamData aParam, ref DeviceCalibration aCalib)
        {
            OnCommand?.Invoke(SystemId, mode, index, flag, ref aParam, ref aCalib);
        }

        #endregion

        #region TIMER EVENT

        private void tmrDisplay_Tick(object sender, EventArgs e)
        {

            DisplayValue();
            OnUpdate?.Invoke(this);
        }

        #endregion

        #region DISPLAY DATA

        private void DisplayValue()
        {
            // Cell Voltage Parameter
            EtcStatusView.UpdateData(SystemData);
        }

        #endregion
    }
}