package com.aiosman.ravenow.ui.network

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
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.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.aiosman.ravenow.LocalAppTheme
import com.aiosman.ravenow.R


//关注、粉丝、通知、like界面网络缺省图
@Composable
fun NetworkErrorContent(
    onReload: () -> Unit,
    modifier: Modifier = Modifier
) {
    val AppColors = LocalAppTheme.current
    
    Box(
        modifier = modifier
            .fillMaxSize()
            .padding(top = 149.dp),
        contentAlignment = Alignment.TopCenter
    ) {
        Column(
            horizontalAlignment = Alignment.CenterHorizontally,
            modifier = Modifier.fillMaxWidth()
        ) {
            Image(
                painter = painterResource(id = R.mipmap.invalid_name_10),
                contentDescription = "network error",
                modifier = Modifier.size(181.dp)
            )
            Spacer(modifier = Modifier.size(24.dp))
            Text(
                text = stringResource(R.string.friend_chat_no_network_title),
                color = AppColors.text,
                fontSize = 16.sp,
                fontWeight = FontWeight.W600
            )
            Spacer(modifier = Modifier.size(8.dp))
            Text(
                text = stringResource(R.string.friend_chat_no_network_subtitle),
                color = AppColors.text,
                fontSize = 14.sp,
                fontWeight = FontWeight.W400
            )
            Spacer(modifier = Modifier.height(16.dp))
            ReloadButton(
                onClick = onReload
            )
        }
    }
}

@Composable
fun NetworkErrorContentInline(
    onReload: () -> Unit,
    modifier: Modifier = Modifier
) {
    val AppColors = LocalAppTheme.current
    
    Column(
        horizontalAlignment = Alignment.CenterHorizontally,
        modifier = modifier.fillMaxWidth()
    ) {
        Image(
            painter = painterResource(id = R.mipmap.invalid_name_10),
            contentDescription = "network error",
            modifier = Modifier.size(140.dp)
        )
        Spacer(modifier = Modifier.height(8.dp))
        Text(
            text = stringResource(R.string.friend_chat_no_network_title),
            color = AppColors.text,
            fontSize = 16.sp,
            fontWeight = FontWeight.W600
        )
        Spacer(modifier = Modifier.height(8.dp))
        Text(
            text = stringResource(R.string.friend_chat_no_network_subtitle),
            color = AppColors.secondaryText,
            fontSize = 14.sp,
            fontWeight = FontWeight.W400
        )
        Spacer(modifier = Modifier.size(16.dp))
        ReloadButton(
            onClick = onReload
        )
    }
}

//消息界面网络缺省图
@Composable
fun NetworkErrorContentCompact(
    onReload: () -> Unit,
    modifier: Modifier = Modifier
) {
    val AppColors = LocalAppTheme.current
    
    Column(
        horizontalAlignment = Alignment.CenterHorizontally,
        modifier = modifier
    ) {
        Image(
            painter = painterResource(id = R.mipmap.invalid_name_10),
            contentDescription = "network error",
            modifier = Modifier.size(120.dp)
        )
        Spacer(modifier = Modifier.height(24.dp))
        Text(
            text = stringResource(R.string.friend_chat_no_network_title),
            color = AppColors.text,
            fontSize = 16.sp,
            fontWeight = FontWeight.W600,
            textAlign = TextAlign.Center,
            modifier = Modifier.padding(horizontal = 24.dp),
            maxLines = 2,
            overflow = TextOverflow.Ellipsis
        )
        Spacer(modifier = Modifier.height(8.dp))
        Text(
            text = stringResource(R.string.friend_chat_no_network_subtitle),
            color = AppColors.secondaryText,
            fontSize = 14.sp,
            textAlign = TextAlign.Center,
            modifier = Modifier.padding(horizontal = 24.dp),
            maxLines = 3,
            overflow = TextOverflow.Ellipsis
        )
        Spacer(modifier = Modifier.height(16.dp))
        ReloadButton(
            onClick = onReload
        )
    }
}

