package com.za.base.view

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Warning
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.za.base.NetworkRouteSelectionActivity
import com.za.base.theme.headBgColor
import com.za.common.GlobalData
import com.za.ext.navigationActivity


val warnBean = mutableStateOf<IWarnBean?>(null)

@Composable
fun AppTipsView() {
	val warnBean by remember { warnBean }

	LaunchedEffect(Unit) {
		fetchAppTipsData()
	}

	when (warnBean) {
		is NetWarnBean -> {
			NetworkWeakView(warnBean as NetWarnBean)
		}

		else -> {}
	}
}


@Composable
fun NetworkWeakView(netWarnBean : NetWarnBean) {
	val context = LocalContext.current

	AnimatedVisibility(context !is NetworkRouteSelectionActivity,
		modifier = Modifier.background(color = headBgColor),
		enter = fadeIn(animationSpec = tween(300)) + expandVertically(animationSpec = tween(300),
			expandFrom = Alignment.Top),
		exit = fadeOut() + shrinkVertically()) {
		Box(modifier = Modifier
			.fillMaxWidth()
			.background(color = Color(0xFFFFF3E0))
			.clickable { }) {
			Row(modifier = Modifier
				.fillMaxWidth()
				.padding(5.dp),
				horizontalArrangement = Arrangement.SpaceBetween,
				verticalAlignment = Alignment.CenterVertically) {
				Row(horizontalArrangement = Arrangement.spacedBy(12.dp),
					verticalAlignment = Alignment.CenterVertically) {
					Box(modifier = Modifier
						.size(30.dp)
						.background(color = Color(0xFFFFE0B2), shape = CircleShape),
						contentAlignment = Alignment.Center) {
						Icon(imageVector = Icons.Rounded.Warning,
							contentDescription = null,
							tint = Color(0xFFFF9800),
							modifier = Modifier.size(24.dp))
					}
					Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
						Text(text = "提醒",
							style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Bold),
							color = Color(0xFF424242),
							fontSize = 14.sp)

						Text(text = "当前线路异常，是否前往切换线路",
							style = MaterialTheme.typography.bodyMedium,
							color = Color(0xFF757575),
							fontSize = 12.sp)
					}
				}

				Box(modifier = Modifier
					.clickable {
						context.navigationActivity(NetworkRouteSelectionActivity::class.java)
					}
					.background(color = Color(0xFFFF9800), shape = RoundedCornerShape(5.dp))
					.padding(horizontal = 10.dp, vertical = 5.dp),
					contentAlignment = Alignment.Center) {
					Text("去完成", color = Color.White, style = MaterialTheme.typography.labelLarge)
				}
			}
		}
	}
}


private fun fetchAppTipsData() {
	if (GlobalData.currentOrder != null) {
		return
	}
	if (GlobalData.token == null) {
		return
	}
}

abstract class IWarnBean

//网络信号强度
data class NetWarnBean(val message : String = "当前网络信息差") : IWarnBean()

data class ReadTrainingCountBean(val mustReadTrainingCount : Int? = null,
	val TrainingCount : Int? = null) : IWarnBean()

//gps掉线
data class GpsOfflineBean(val message : String = "Gps掉线了") : IWarnBean()

//gps信号弱
data class GpsWeakBean(val message : String = "Gps信号弱") : IWarnBean()

sealed class WarnType {
	object ALl : WarnType()
	object NULL : WarnType()
	object NetWarn : WarnType()
	object GpsOffline : WarnType()
	object GpsWeak : WarnType()
}