package com.aiosman.ravenow.ui.index

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
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.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.BottomSheetDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.SheetState
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.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.res.stringResource
import com.aiosman.ravenow.LocalAppTheme
import com.aiosman.ravenow.R
import com.aiosman.ravenow.ui.modifiers.noRippleClickable

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CreateBottomSheet(
    sheetState: SheetState,
    onDismiss: () -> Unit,
    onAiClick: () -> Unit,
    onGroupChatClick: () -> Unit,
    onMomentClick: () -> Unit
) {
    val appColors = LocalAppTheme.current
//水平效果呈现镜像排列
    ModalBottomSheet(
        onDismissRequest = onDismiss,
        sheetState = sheetState,
        windowInsets = BottomSheetDefaults.windowInsets,
        containerColor = appColors.background,
        dragHandle = null,
        shape = RoundedCornerShape(topStart = 20.dp, topEnd = 20.dp)
    ) {
        Column(
            modifier = Modifier
                .fillMaxWidth()
                .padding(top = 24.dp, bottom = 24.dp),
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            Row(
                modifier = Modifier.fillMaxWidth(),
                verticalAlignment = Alignment.CenterVertically
            ) {
                Image(
                    painter = painterResource(R.mipmap.h_cj_rw_icon),
                    contentDescription = null,
                    modifier = Modifier
                        .padding(start = 16.dp),
                    colorFilter = androidx.compose.ui.graphics.ColorFilter.tint(appColors.text)
                )
                Spacer(modifier = Modifier.weight(1f))
                Text(
                    text = stringResource(R.string.create_title),
                    fontSize = 18.sp,
                    fontWeight = FontWeight.Bold,
                    color = appColors.text,
                    modifier = Modifier
                        .padding(end = 3.dp)
                )
                Image(
                    painter = painterResource(R.mipmap.h_cj_x_img),
                    contentDescription = null,
                    modifier = Modifier
                        .padding(end = 18.dp),
                    colorFilter = androidx.compose.ui.graphics.ColorFilter.tint(appColors.text)
                )
            }

            Spacer(modifier = Modifier.height(30.dp))
            // 三个创建选项
            Row(
                modifier = Modifier.fillMaxWidth(),
                horizontalArrangement = Arrangement.SpaceEvenly
            ) {
                // 动态选项
                CreateOption(
                    icon = R.drawable.ic_create_monent,
                    label = stringResource(R.string.create_moment),
                    onClick = onMomentClick
                )
                // 群聊选项
                CreateOption(
                    icon = R.mipmap.icons_circle_camera,
                    label = stringResource(R.string.create_group_chat_option),
                    onClick = onGroupChatClick
                )
                // AI选项
                CreateOption(
                    icon = R.mipmap.icons_circle_ai,
                    label = stringResource(R.string.create_ai),
                    onClick = onAiClick
                )
            }
            
            Spacer(modifier = Modifier.height(40.dp))
            
            // 关闭按钮
            Box(
                modifier = Modifier
                    .size(32.dp)
                    .clip(CircleShape)
                    .noRippleClickable { onDismiss() },
                contentAlignment = Alignment.Center
            ) {
                Image(
                    painter = painterResource(R.drawable.ic_create_close),
                    contentDescription = stringResource(R.string.create_close),
                    modifier = Modifier.size(32.dp)
                )
            }
            
            Spacer(modifier = Modifier.height(16.dp))
        }
    }
}

@Composable
private fun CreateOption(
    icon: Int,
    label: String,
    onClick: () -> Unit
) {
    val appColors = LocalAppTheme.current
    
    Column(
        horizontalAlignment = Alignment.CenterHorizontally,
        modifier = Modifier.noRippleClickable { onClick() }
    ) {
        // 直接使用图标，不要背景
        Image(
            painter = painterResource(icon),
            contentDescription = label,
            modifier = Modifier.size(72.dp)
        )
        
        Spacer(modifier = Modifier.height(12.dp))
        
        // 文字标签
        Text(
            text = label,
            fontSize = 14.sp,
            fontWeight = FontWeight.Medium,
            color = appColors.text
        )
    }
}
