package com.aiosman.ravenow.ui.index.tabs.profile.composable

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
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.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Clear
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
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.unit.dp
import androidx.compose.ui.unit.sp
import com.aiosman.ravenow.AppState
import com.aiosman.ravenow.GuestLoginCheckOut
import com.aiosman.ravenow.GuestLoginCheckOutScene
import com.aiosman.ravenow.LocalAppTheme
import com.aiosman.ravenow.LocalNavController
import com.aiosman.ravenow.R
import com.aiosman.ravenow.ui.NavigationRoute
import com.aiosman.ravenow.entity.AccountProfileEntity
import com.aiosman.ravenow.ui.modifiers.noRippleClickable

@Composable
fun OtherProfileAction(
    profile: AccountProfileEntity,
    onFollow: (() -> Unit)? = null,
    onChat: (() -> Unit)? = null
) {
    val AppColors = LocalAppTheme.current
    val navController = LocalNavController.current
    
    // 定义渐变色
    val followGradient = Brush.horizontalGradient(
        colors = listOf(
            Color(0xFFE53E3E), // 红色
            Color(0xFF9F7AEA)  // 紫色
        )
    )
    
    Row(
        verticalAlignment = Alignment.CenterVertically,
        horizontalArrangement = Arrangement.spacedBy(12.dp),
        modifier = Modifier.fillMaxWidth()
    ) {
        // 关注按钮 - 渐变样式
        Row(
            verticalAlignment = Alignment.CenterVertically,
            horizontalArrangement = Arrangement.Center,
            modifier = Modifier
                .weight(1f)
                .clip(RoundedCornerShape(8.dp))
                .let { modifier ->
                    if (profile.isFollowing) {
                        // 已关注状态 - 透明背景
                        modifier.background(Color.Transparent)
                    } else {
                        // 未关注状态 - 渐变背景
                        modifier.background(brush = followGradient)
                    }
                }
                .let { modifier ->
                    if (profile.isFollowing) {
                        modifier.border(
                            width = 1.dp,
                            color = AppColors.text.copy(alpha = 0.3f),
                            shape = RoundedCornerShape(8.dp)
                        )
                    } else {
                        modifier
                    }
                }
                .padding(horizontal = 16.dp, vertical = 12.dp)
                .noRippleClickable {
                    // 检查游客模式，如果是游客则跳转登录
                    if (GuestLoginCheckOut.needLogin(GuestLoginCheckOutScene.FOLLOW_USER)) {
                        navController.navigate(NavigationRoute.Login.route)
                    } else {
                        onFollow?.invoke()
                    }
                }
        ) {
            Text(
                text = if (profile.isFollowing) "已关注" else stringResource(R.string.follow_upper),
                fontSize = 14.sp,
                fontWeight = FontWeight.W600,
                color = if (profile.isFollowing) {
                    // 已关注状态 - 灰色文字
                    AppColors.text.copy(alpha = 0.6f)
                } else {
                    // 未关注状态 - 白色文字
                    Color.White
                },
            )
        }
        
        // 私信按钮 - 灰色背景样式
        if (AppState.enableChat) {
            Row(
                verticalAlignment = Alignment.CenterVertically,
                horizontalArrangement = Arrangement.Center,
                modifier = Modifier
                    .weight(1f)
                    .clip(RoundedCornerShape(8.dp))
                    .background(AppColors.nonActive) // 使用主题灰色背景
                    .padding(horizontal = 16.dp, vertical = 12.dp)
                    .noRippleClickable {
                        // 检查游客模式，如果是游客则跳转登录
                        if (GuestLoginCheckOut.needLogin(GuestLoginCheckOutScene.CHAT_WITH_AGENT)) {
                            navController.navigate(NavigationRoute.Login.route)
                        } else {
                            onChat?.invoke()
                        }
                    }
            ) {
                Text(
                    text = stringResource(R.string.chat_upper),
                    fontSize = 14.sp,
                    fontWeight = FontWeight.W600,
                    color = AppColors.text, // 使用主题文字颜色
                )
            }
        }
    }

}