package com.ys.bdtp.adm.mvvm.ui.screen.project

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.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.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.ys.bdtp.adm.R
import com.ys.bdtp.adm.mvvm.model.db.entity.task.ProjectEntity
import com.ys.bdtp.adm.mvvm.ui.screen.main.LocalNavHostController
import com.ys.bdtp.adm.mvvm.ui.screen.main.Route

@Composable
fun ProjectItem(project: ProjectEntity) {
    val nav = LocalNavHostController.current!!
    Card(
        modifier = Modifier
            .fillMaxWidth()
            .height(170.dp),
        backgroundColor = Color.White,
        shape = RoundedCornerShape(8),
        border = BorderStroke(0.8.dp, Color(0xFFE5E5E5)),
        elevation = 0.dp
    ) {
        Row(
            modifier = Modifier
                .clickable {
                    nav.navigate("${Route.Task}/${project.projectId}")
                }
                .padding(20.dp),
            verticalAlignment = Alignment.CenterVertically
        ) {

            Image(
                painter = painterResource(R.drawable.project_item_placeholder),
                contentDescription = "",
                modifier = Modifier.width(130.dp).height(130.dp)
            )

            Spacer(modifier = Modifier.width(35.dp))

            Column(
                modifier = Modifier.fillMaxHeight(),
                verticalArrangement = Arrangement.SpaceAround
            ) {
                Text(text = project.projectName, color = Color(0xFF1F2429), fontSize = 20.sp)
                Text(text = "项目ID:${project.projectId}", color = Color(0xFF1F2429), fontSize = 16.sp)
                Text(text = "项目角色:暂无", color = Color(0xFF1F2429), fontSize = 16.sp)
            }
        }
    }
}

@Preview
@Composable
fun PreviewProjectItem() {
    ProjectItem(
        ProjectEntity(
            projectId = "112233",
            projectName = "京东科技大厦",
            groupCode = "JD",
            groupName = "京东"
        )
    )
}