package com.za.base.view

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
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.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage
import com.za.servicing.R

@Composable
fun EmptyView(
    modifier: Modifier = Modifier,
    message: String = "暂无数据",
    imageSize: Pair<Int, Int> = Pair(118, 143),
    imageRes: Int = R.drawable.sv_emty_data
) {
    Column(
        modifier = modifier.fillMaxSize(),
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        AsyncImage(
            model = imageRes,
            contentDescription = message,
            modifier = Modifier.size(imageSize.first.dp, imageSize.second.dp)
        )
        
        Spacer(modifier = Modifier.height(12.dp))
        
        Text(
            text = message,
            color = Color.Gray,
            fontSize = 14.sp,
            textAlign = TextAlign.Center
        )
    }
}

@Composable
fun LoadError(
    modifier: Modifier = Modifier,
    message: String = "加载出错",
    imageSize: Pair<Int, Int> = Pair(118, 143),
    onRetry: (() -> Unit)? = null
) {
    Column(
        modifier = modifier.fillMaxSize(),
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        AsyncImage(
            model = R.drawable.sv_load_error,
            contentDescription = message,
            modifier = Modifier.size(imageSize.first.dp, imageSize.second.dp)
        )
        
        Spacer(modifier = Modifier.height(12.dp))
        
        Text(
            text = message,
            color = Color.Gray,
            fontSize = 14.sp,
            textAlign = TextAlign.Center
        )
        
        if (onRetry != null) {
            Spacer(modifier = Modifier.height(16.dp))
            
            Text(
                text = "点击重试",
                color = Color(0xFF1BA8F7),
                fontSize = 14.sp,
                modifier = Modifier
                    .align(Alignment.CenterHorizontally)
                    .clickable { onRetry() }
            )
        }
    }
}