package com.zaojiao.app.feat.home.index

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.fillMaxHeight
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.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.draw.clip
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.zaojiao.app.feat.home.R
import com.zaojiao.component.common.Colors
import com.zaojiao.component.common.Expanded
import com.zaojiao.component.common.Icons
import com.zaojiao.component.common.Spacer
import com.zaojiao.component.common.shadow

@Composable
fun HomeIndexCourse() {
    Column(
        modifier = Modifier
            .padding(horizontal = 16.dp, vertical = 20.dp)
            .wrapContentHeight()
            .fillMaxWidth()
    ) {
        HomeIndexCourseTitle()
    }
}

@Composable
fun HomeIndexCourseTitle() {
    Row(
        modifier = Modifier.wrapContentHeight(),
        verticalAlignment = Alignment.CenterVertically,
    ) {

        Text(
            text = "好课榜单",
            style = TextStyle(
                fontSize = 18.sp,
                lineHeight = 18.sp,
                fontWeight = FontWeight.SemiBold,
                color = Colors.FF333333,
            ),
        )

        Expanded()

        Text(
            text = "更多",
            style = TextStyle(
                fontSize = 12.sp,
                lineHeight = 16.sp,
                fontWeight = FontWeight.Normal,
                color = Colors.FF999999,
            ),
        )
        Spacer(width = 4.dp)

        Icons.Forward(
            size = Size(3.6f, 6f),
            color = Colors.FF999999,
            width = 0.5.dp,
        )
    }
}

@Composable
fun HomeIndexCourseRecommendItem() {
    Box(
        modifier = Modifier
            .padding(horizontal = 8.dp)
            .clip(RoundedCornerShape(20.dp))
            .shadow(
                color = Colors.from("#99E7EDF1"),
                offsetY = 4.dp,
                blurRadius = 19.dp,
                spreadSize = 4.dp,
            )
            .background(color = Color.White)
            .padding(12.dp)
            .wrapContentHeight()
            .fillMaxWidth(),
    ) {
        Row(
            modifier = Modifier.fillMaxWidth()
        ) {
            Image(
                painter = painterResource(id = R.mipmap.default_avatar),
                contentDescription = "课程封面",
                contentScale = ContentScale.Crop,
                modifier = Modifier
                    .clip(RoundedCornerShape(10.dp))
                    .size(115.dp),
            )
            Spacer(width = 12.dp)
            Column(
                modifier = Modifier
                    .weight(1f)
                    .height(115.dp),
                horizontalAlignment = Alignment.Start,
            ) {
                Text(
                    text = "逻辑狗好盆友逻辑狗好辑狗好盆友逻辑狗好辑狗好盆友逻辑狗好",
                    maxLines = 1,
                    overflow = TextOverflow.Ellipsis,
                    style = TextStyle(
                        fontSize = 16.sp,
                        lineHeight = 22.sp,
                        fontWeight = FontWeight.SemiBold,
                        color = Colors.FF333333,
                    ),
                )
                Spacer(height = 19.dp)
                Text(
                    text = "34万人学过",
                    style = TextStyle(
                        fontSize = 12.sp,
                        lineHeight = 12.sp,
                        fontWeight = FontWeight.Normal,
                        color = Colors.FF999999,
                    ),
                )
                Expanded()
                Text(
                    text = "免费",
                    style = TextStyle(
                        fontSize = 16.sp,
                        lineHeight = 16.sp,
                        fontWeight = FontWeight.Medium,
                        color = Colors.from("#FFFF5749"),
                    ),
                )
                Spacer(height = 6.dp)
            }
        }
    }
}
