package com.zaojiao.app.feat.home.personal

import androidx.annotation.DrawableRes
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.RowScope
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.shape.RoundedCornerShape
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.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.zaojiao.app.feat.home.R
import com.zaojiao.app.feat.design.shadow

@Composable
fun HomePersonalContent(
    navToPageWithLogin: (route: String) -> Unit,
    navToPageWithoutLogin: (route: String) -> Unit,
) {
    Box(
        modifier = Modifier
            .padding(
                horizontal = 8.dp,
                vertical = 4.dp,
            )
            .shadow(
                color = Color(0xFFF4F4F4),
                offsetX = 0.dp,
                offsetY = 2.dp,
                blurRadius = 6.dp,
                shadowRadius = 20.dp,
            )
            .background(
                color = Color.White,
                shape = RoundedCornerShape(20.dp),
            ),
    ) {
        Column(
            modifier = Modifier
                .wrapContentHeight()
                .fillMaxWidth(),
        ) {
            Box(modifier = Modifier.height(16.dp))

            Box(
                modifier = Modifier.padding(start = 14.dp),
            ) {
                Text(
                    text = "我的内容",
                    style = TextStyle(
                        fontSize = 16.sp,
                        lineHeight = 16.sp,
                        letterSpacing = 0.38.sp,
                        fontWeight = FontWeight.Medium,
                        color = Color(0xFF333333),
                    ),
                )
            }

            Box(modifier = Modifier.height(18.dp))
            Row(
                modifier = Modifier
                    .fillMaxWidth()
                    .wrapContentHeight(),
                horizontalArrangement = Arrangement.SpaceBetween,
            ) {
                HomePersonalContentItem(
                    iconRes = R.mipmap.personal_history,
                    description = "观看历史"
                )
                HomePersonalContentItem(
                    iconRes = R.mipmap.personal_orders,
                    description = "全部订单"
                )
                HomePersonalContentItem(
                    iconRes = R.mipmap.personal_course,
                    description = "我的课程"
                )
                HomePersonalContentItem(
                    iconRes = R.mipmap.personal_report,
                    description = "成长报告"
                )
            }
            Box(modifier = Modifier.height(27.dp))
        }
    }
}

@Composable
fun RowScope.HomePersonalContentItem(
    @DrawableRes iconRes: Int,
    description: String,
) {
    Column(
        modifier = Modifier
            .weight(1f)
            .fillMaxHeight()
            .widthIn(max = 56.dp),
        verticalArrangement = Arrangement.SpaceBetween,
        horizontalAlignment = Alignment.CenterHorizontally,
    ) {
        Image(
            painter = painterResource(id = iconRes),
            contentDescription = description,
            modifier = Modifier
                .width(44.dp)
                .height(44.dp)
        )
        Box(modifier = Modifier.height(5.dp))
        Text(
            text = description,
            style = TextStyle(
                fontSize = 12.sp,
                lineHeight = 12.sp,
                fontWeight = FontWeight.Normal,
                color = Color(0xFF333333),
            ),
        )
    }
}