package com.zaojiao.component.common

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.sp

enum class PageState { Idle, Running, Success, Error }

@Composable
fun StatePage(state: PageState, onSuccess: @Composable () -> Unit) {
    when (state) {
        PageState.Idle -> {
            Box(
                modifier = Modifier.fillMaxSize(),
            ) {
                Text(
                    text = "idle state",
                    modifier = Modifier.align(Alignment.Center),
                    style = TextStyle(
                        fontSize = 18.sp,
                        color = Color.Green,
                    )
                )
            }
        }

        PageState.Running -> {
            Box(
                modifier = Modifier.fillMaxSize(),
            ) {
                Text(
                    text = "running state",
                    modifier = Modifier.align(Alignment.Center),
                    style = TextStyle(
                        fontSize = 18.sp,
                        color = Color.Cyan,
                    )
                )
            }
        }

        PageState.Success -> {
            onSuccess.invoke()
        }

        PageState.Error -> {
            Box(
                modifier = Modifier.fillMaxSize(),
            ) {
                Text(
                    text = "error state",
                    modifier = Modifier.align(Alignment.Center),
                    style = TextStyle(
                        fontSize = 18.sp,
                        color = Color.Red,
                    )
                )
            }
        }
    }
}