using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using arDev;
using AR;

namespace Project
{
	public partial class FMain
	{

		private void SM_StateProgress(object sender, AR.StateMachine.StateProgressEventArgs e)
		{
			arCtl.arLabel lbl = lbMsg;

			lbl.BeginInvoke(new Action(() =>
			{
				var title = e.Message;
				var max = e.MaxProgress;
				var value = e.Progress;


				if (lbl.ProgressEnable == false) lbl.ProgressEnable = true;
				if (lbl.ProgressValue != value) lbl.ProgressValue = (float)value;
				if (lbl.Text != title) lbl.Text = title;

				if (max != 0)
				{
					if (lbl.ProgressMax != max) lbl.ProgressMax = (float)max;
				}
				if (e.ForeColor != null)
				{
					if (lbl.ProgressForeColor != e.ForeColor) lbl.ProgressForeColor = (Color)e.ForeColor;
				}
				if (e.ShadowColor != null)
				{
					if (lbl.ShadowColor != e.ShadowColor) lbl.ShadowColor = (Color)e.ShadowColor;
				}
				if (e.ProgressBackColor1 != null)
				{
					if (lbl.ProgressColor1 != e.ProgressBackColor1) lbl.ProgressColor1 = (Color)e.ProgressBackColor1;
				}
				if (e.ProgressBackColor2 != null)
				{
					if (lbl.ProgressColor2 != e.ProgressBackColor2) lbl.ProgressColor1 = (Color)e.ProgressBackColor2;
				}

				if (e.BackColor1 != null)
				{
					if (lbl.BackColor != e.BackColor1) lbl.BackColor = (Color)e.BackColor1;
				}
				if (e.BackColor2 != null)
				{
					if (lbl.BackColor2 != e.BackColor2) lbl.BackColor2 = (Color)e.BackColor2;
				}
			}));
		}

		private void SM_StepCompleted(object sender, EventArgs e)
		{
			PUB.log.Add($"Step completed({PUB.sm.Step})");

			//초기화가 완료되면 컨트롤 글자를 변경 해준다.
			if (PUB.sm.Step == eSMStep.INIT)
				SM_InitControl(null, null);

		}

		private void SM_StepStarted(object sender, EventArgs e)
		{
			switch (PUB.sm.Step)
			{
				case eSMStep.IDLE:

					//IDLE의 시작작업이 완료되었다면 각 버튼을 사용할 수 있도록 한다
					this.Invoke(new Action(() =>
					{
						btStart.Enabled = true;
						btStop.Enabled = true;
						btReset.Enabled = true;
					}));

					break;
			}

		}

		private void SM_InitControl(object sender, EventArgs e)
		{
			//작업시작전 컨트롤 초기화 코드
			var mc = PUB.Result.mModel;
			var mv = PUB.Result.vModel;

			this.Invoke(new Action(() =>
			{

				//진행 중 표시되는 상태값 초기화
				lbCntRight.ProgressValue = 0;
				lbCntRight.Text = "--";
				lbCntLeft.Text = "--";
			}));

		}



		void SM_Message(object sender, StateMachine.StateMachineMessageEventArgs e)
		{
			//상태머신에서 발생한 메세지
			PUB.log.Add(e.Header, e.Message);
		}


		void SM_StepChanged(object sender, StateMachine.StepChangeEventArgs e)
		{
			var o = (eSMStep)e.Old;
			var n = (eSMStep)e.New;
			PUB.log.AddI($"Step transition({o} >> {n})");

			//230313
			//EEMStatus.AddStatusSQL(n);
		}

	}
}
