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

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
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.text.font.FontWeight
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 androidx.compose.foundation.lazy.items
import androidx.compose.material.LinearProgressIndicator
import androidx.compose.material.Surface
import androidx.compose.ui.text.style.TextAlign

// 3 7
@Composable
fun ProjectTask() {
    Row(modifier = Modifier.fillMaxSize().background(Color.White)) {
        Column(
            modifier = Modifier
                .fillMaxHeight()
                .wrapContentWidth()
                .padding(horizontal = 32.dp, vertical = 42.dp)
        ) {
            Column(
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                TaskType(R.drawable.project_task_cad, "CAD核查")
                Spacer(modifier = Modifier.height(20.dp))
                TaskType(R.drawable.project_task_space, "空间模型核查")
                Spacer(modifier = Modifier.height(20.dp))
                TaskType(R.drawable.project_task_electric, "机电核查")
                Spacer(modifier = Modifier.height(20.dp))
                TaskType(R.drawable.project_task_relation, "交付关系")
                Spacer(modifier = Modifier.height(20.dp))
                TaskType(R.drawable.project_task_offline, "离线数据")
            }
        }
        Spacer(modifier = Modifier.width(1.dp).fillMaxHeight().background(Color(0xFFE5E5E5)))

        Column(
            modifier = Modifier
                .fillMaxHeight()
                .padding(horizontal = 48.dp, vertical = 44.dp)
        ) {
            Text(
                text = "近期负责的项目任务",
                fontSize = 16.sp,
                fontWeight = FontWeight.Bold,
                color = Color(0xFF1F2429),
                modifier = Modifier.height(20.dp)
            )
            Spacer(modifier = Modifier.fillMaxWidth().height(20.dp))
            Row(
                modifier = Modifier
                    .fillMaxWidth()
                    .height(40.dp)
                    .background(Color(0xFFF8F9FA)),
                verticalAlignment = Alignment.CenterVertically,
                horizontalArrangement = Arrangement.SpaceAround

            ) {
                Text(
                    text = "项目名称",
                    fontSize = 16.sp,
                    color = Color(0xFF646C73),
                    textAlign = TextAlign.Center,
                    modifier = Modifier.weight(20f)
                )
                Text(
                    text = "楼层",
                    fontSize = 16.sp,
                    color = Color(0xFF646C73),
                    textAlign = TextAlign.Center,
                    modifier = Modifier.weight(20f)
                )
                Text(
                    text = "起始时间",
                    fontSize = 16.sp,
                    color = Color(0xFF646C73),
                    textAlign = TextAlign.Center,
                    modifier = Modifier.weight(25f)
                )
                Text(
                    text = "项目完成进度",
                    fontSize = 16.sp,
                    color = Color(0xFF646C73),
                    textAlign = TextAlign.Center,
                    modifier = Modifier.weight(33f)
                )
            }

            LazyColumn(modifier = Modifier.fillMaxWidth().height(436.dp)) {
                items(20) {
                    Box {
                        Row(
                            modifier = Modifier
                                .fillMaxWidth()
                                .height(48.dp)
                                .background(Color.White),
                            verticalAlignment = Alignment.CenterVertically,
                            horizontalArrangement = Arrangement.SpaceEvenly
                        ) {
                            Text(
                                text = "项目名称",
                                fontSize = 16.sp,
                                color = Color(0xFF1F2429),
                                textAlign = TextAlign.Center,
                                modifier = Modifier.weight(20f)
                            )
                            Text(
                                text = "楼层",
                                fontSize = 16.sp,
                                color = Color(0xFF1F2429),
                                textAlign = TextAlign.Center,
                                modifier = Modifier.weight(20f)
                            )
                            Text(
                                text = "起始时间",
                                fontSize = 16.sp,
                                color = Color(0xFF1F2429),
                                textAlign = TextAlign.Center,
                                modifier = Modifier.weight(25f)
                            )
                            Row(
                                modifier = Modifier.weight(33f),
                                verticalAlignment = Alignment.CenterVertically,
                                horizontalArrangement = Arrangement.Center
                            ) {
                                Surface(
                                    elevation = 0.dp,
                                    shape = RoundedCornerShape(10.dp),
                                    modifier = Modifier.weight(4f).height(10.dp),
                                ) {
                                    LinearProgressIndicator(
                                        progress = 0.8f,
                                        color = Color(0xFF0091FF),
                                        backgroundColor = Color(0xFFF9F9F9),
                                    )
                                }
                                Spacer(modifier = Modifier.width(16.dp))
                                Text(
                                    text = "40%",
                                    fontSize = 16.sp,
                                    color = Color(0xFF1F2429),
                                    textAlign = TextAlign.Start,
                                    modifier = Modifier.weight(2f)
                                )
                            }
                        }
                        Spacer(
                            modifier = Modifier
                                .align(Alignment.BottomCenter)
                                .fillMaxWidth().height(1.dp)
                                .background(Color(0xFFE4E6E7))
                        )
                    }

                }
            }
            Spacer(modifier = Modifier.fillMaxWidth().height(40.dp))
            Text(
                text = "查看全部项目任务",
                fontSize = 14.sp,
                color = Color(0xFF0091FF),
                textAlign = TextAlign.Center,
                modifier = Modifier.fillMaxWidth()
            )
        }
    }
}


@Composable
fun TaskType(resId: Int, title: String) {
    Card(
        shape = RoundedCornerShape(8),
        border = BorderStroke(1.dp, Color(0xFFE5E5E5)),
        elevation = 0.dp
    ) {
        Row(
            modifier = Modifier
                .width(314.dp)
                .height(88.dp)
                .background(Color.White)
                .padding(horizontal = 20.dp, vertical = 15.dp),
            verticalAlignment = Alignment.CenterVertically
        ) {
            Image(
                painter = painterResource(resId),
                contentDescription = "",
                modifier = Modifier
                    .width(58.dp)
                    .height(58.dp)
            )
            Spacer(modifier = Modifier.width(20.dp))
            Text(text = title, fontSize = 16.sp, fontWeight = FontWeight.Bold)
        }
    }
}

@Preview(widthDp = 1280, heightDp = 800)
@Composable
fun PreviewProjectTask() {
    ProjectTask()
}
/*

@Preview
@Composable
fun PreviewTaskType1() {
    TaskType(R.drawable.project_task_cad, "CAD核查")
}

@Preview
@Composable
fun PreviewTaskType2() {
    TaskType(R.drawable.project_task_space, "空间模型核查")
}

@Preview
@Composable
fun PreviewTaskType3() {
    TaskType(R.drawable.project_task_electric, "机电核查")
}

@Preview
@Composable
fun PreviewTaskType4() {
    TaskType(R.drawable.project_task_relation, "交付关系")
}

@Preview
@Composable
fun PreviewTaskType5() {
    TaskType(R.drawable.project_task_offline, "离线数据")
}*/
