package com.aiosman.ravenow.ui.account

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
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.LocalNavController
import com.aiosman.ravenow.R
import com.aiosman.ravenow.ui.composables.StatusBarSpacer
import com.aiosman.ravenow.ui.modifiers.noRippleClickable

private object BlockedUsersConstants {
    const val BACK_BUTTON_SIZE = 36
    const val BACK_BUTTON_ICON_SIZE = 24
    const val BACK_BUTTON_START_PADDING = 19
    const val HEADER_VERTICAL_PADDING = 16
    const val TITLE_OFFSET_X = 19
    const val TITLE_TEXT_SIZE = 17
}

@Composable
private fun CircularBackButton(
    onClick: () -> Unit,
    modifier: Modifier = Modifier
) {
    val appColors = LocalAppTheme.current
    Image(
        painter = painterResource(id = R.drawable.rider_pro_back_icon),
        contentDescription = "返回",
        modifier = modifier
            .size(BlockedUsersConstants.BACK_BUTTON_ICON_SIZE.dp)
            .noRippleClickable { onClick() },
        colorFilter = ColorFilter.tint(appColors.text)
    )
}

/**
 * 被屏蔽的用户界面
 */
@Composable
fun BlockedUsersScreen() {
    val appColors = LocalAppTheme.current
    val navController = LocalNavController.current
    
    Column(
        modifier = Modifier
            .fillMaxSize()
            .background(appColors.background),
    ) {
        StatusBarSpacer()
        
        // 顶部标题栏
        Box(
            modifier = Modifier
                .fillMaxWidth()
                .padding(vertical = BlockedUsersConstants.HEADER_VERTICAL_PADDING.dp)
        ) {
            Row(
                modifier = Modifier.fillMaxWidth(),
                verticalAlignment = Alignment.CenterVertically
            ) {
                CircularBackButton(
                    onClick = { navController.navigateUp() },
                    modifier = Modifier.padding(start = BlockedUsersConstants.BACK_BUTTON_START_PADDING.dp)
                )
                Spacer(modifier = Modifier.width(12.dp))
                Text(
                    text = stringResource(R.string.blocked_users),
                    fontWeight = FontWeight.W800,
                    fontSize = BlockedUsersConstants.TITLE_TEXT_SIZE.sp,
                    color = appColors.text
                )
            }
        }
        
        // 缺省状态
        Box(
            modifier = Modifier
                .fillMaxSize()
                .padding(top = 149.dp),
            contentAlignment = Alignment.TopCenter
        ) {
            Column(
                horizontalAlignment = Alignment.CenterHorizontally,
                modifier = Modifier.fillMaxWidth()
            ) {
                Image(
                    painter = painterResource(id = R.mipmap.frame_23),
                    contentDescription = null,
                    modifier = Modifier.size(181.dp, 153.dp)
                )
                Spacer(modifier = Modifier.size(9.dp))
                Text(
                    text = stringResource(R.string.no_users_isolated_yet),
                    color = appColors.text,
                    fontSize = 16.sp,
                    fontWeight = FontWeight.W600,
                    textAlign = TextAlign.Center,
                    modifier = Modifier.padding(horizontal = 24.dp),
                    maxLines = 2,
                    overflow = TextOverflow.Ellipsis
                )
            }
        }
    }
}

