package com.za.base.view

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import coil.decode.GifDecoder
import coil.request.ImageRequest
import com.za.servicing.R


object LoadingManager {
	val showLoading = mutableStateOf(false)

	fun showLoading() {
		showLoading.value = true
	}

	fun hideLoading() {
		showLoading.value = false
	}

	@Composable
	fun LoadingView() {
		Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) {
			AsyncImage(model = ImageRequest.Builder(LocalContext.current)
				.data(R.drawable.gif_loading).decoderFactory(GifDecoder.Factory()).build(),
				contentDescription = "加载中",
				modifier = Modifier
					.size(70.dp)
					.align(Alignment.Center))
		}
	}
}

open class LoadingState {
	data object Loading : LoadingState()
	data class LoadingFailed(val msg : String? = "加载失败") : LoadingState()
	data object LoadingSuccess : LoadingState()
}