package controller

import (
	. "netease_control_center/globals"
)

var (
	ledShowChan       = make(chan uint8, 1)
	backupVolume int8 = -1

	togaltest = false
)

func triggerLedShow() {
	return
	select {
	case ledShowChan <- 0:
	default:
	}
}

func UpdateMicLedsStauts() {
	CloseAll := true
	//1. check volume
	if IsSettingVolume {
		curVol, _ := VolGet()
		if CurMicLedStatus != MicLedStatuses_VOLUME || (CurMicLedStatus == MicLedStatuses_VOLUME && int(backupVolume) != curVol) {
			backupVolume = int8(curVol)
			CurMicLedStatus = MicLedStatuses_VOLUME
			triggerLedShow()
		}
		return
	}

	// Wifi paring status
	switch CurBootState {
	case BootStage_WIFIPARING:
		if CurMicLedStatus != MicLedStatuses_WIFIPARING {
			CurMicLedStatus = MicLedStatuses_WIFIPARING
			triggerLedShow()
		}
		return
	}

	//2. mic close
	if IsMicClose {
		if CurMicLedStatus != MicLedStatuses_ALLCLOSE {
			CurMicLedStatus = MicLedStatuses_ALLCLOSE
			triggerLedShow()
		}
		return
	}

	//3. voice status
	switch CurVoiceStatus {
	case VoiceStatus_WAKEUP:
		if CurMicLedStatus != MicLedStatuses_WAKEUP {
			CurMicLedStatus = MicLedStatuses_WAKEUP
		}
		triggerLedShow()
		return

	case VoiceStatus_RECOGING:
		if CurMicLedStatus != MicLedStatuses_RECOGING {
			CurMicLedStatus = MicLedStatuses_RECOGING
			triggerLedShow()
		}
		return

	case VoiceStatus_ERROR:
		if CurMicLedStatus != MicLedStatuses_RECOGERROR {
			CurMicLedStatus = MicLedStatuses_RECOGERROR
			triggerLedShow()
		}
		return

	case VoiceStatus_FINISH:
		if CurMicLedStatus != MicLedStatuses_KEEP_AND_STOP {
			CurMicLedStatus = MicLedStatuses_KEEP_AND_STOP
			triggerLedShow()
		}
		CurVoiceStatus = VoiceStatus_IDLE
		return
	case VoiceStatus_IDLE:
		//do nothing
	}

	//lowest cheking, close all
	if CurMicLedStatus != MicLedStatuses_ALLCLOSE && CloseAll == true {
		CurMicLedStatus = MicLedStatuses_ALLCLOSE
		triggerLedShow()
	}
}

func SetMicLedMode(st MicLedStatuses) {
	if st >= MicLedStatuses_MAX {
		return
	}

	CurMicLedStatus = st
	UpdateMicLedsStauts()
}
