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.fillMaxSize
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.wrapContentHeight
import androidx.compose.foundation.lazy.LazyRow
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.blur
import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.Size
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.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.list

@Composable
fun HomeIndexTopic() {
    Column(
        modifier = Modifier
            .padding(horizontal = 16.dp, vertical = 20.dp)
            .wrapContentHeight()
            .fillMaxWidth()
    ) {
        HomeIndexTopicTitle()
        Spacer(height = 20.dp)
        HomeIndexTopicRecommend()
    }
}

@Composable
fun HomeIndexTopicTitle() {
    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 HomeIndexTopicRecommend() {
    LazyRow(
        modifier = Modifier
            .height(202.dp)
            .fillMaxWidth(),
    ) {
        list(
            count = 10,
            itemSeparation = {
                Box(modifier = Modifier.width(12.dp))
            },
            itemContent = {
                HomeIndexTopicRecommendItem()
            },
        )
    }

}

@Composable
fun HomeIndexTopicRecommendItem() {
    Box(
        modifier = Modifier
            .clip(RoundedCornerShape(20.dp))
            .width(152.dp)
            .fillMaxHeight()
    ) {
        Image(
            painter = painterResource(id = R.mipmap.default_avatar),
            contentDescription = null,
            contentScale = ContentScale.Crop,
            modifier = Modifier
                .clip(RoundedCornerShape(20.dp))
                .blur(radius = 20.dp)
                .fillMaxSize(),
        )

        Image(
            painter = painterResource(id = R.mipmap.default_avatar),
            contentDescription = null,
            contentScale = ContentScale.Fit,
            modifier = Modifier
                .align(Alignment.TopCenter)
                .fillMaxSize(),
        )

        Column(
            modifier = Modifier
                .align(Alignment.BottomCenter)
                .clip(shape = RoundedCornerShape(20.dp))
                .blur(radius = 20.dp)
                .background(color = Colors.from("#EEFFFFFF"))
                .height(102.dp)
                .fillMaxWidth()
        ) {

        }
    }
}