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

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.border
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.Spacer
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.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Search
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
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.mvvm.ui.compose.Head
import com.ys.bdtp.adm.mvvm.ui.compose.HeadLeft
import com.ys.bdtp.adm.mvvm.ui.compose.HeadRight

@Composable
fun ProjectTaskScreen() {
    var value by remember { mutableStateOf("") }
    Column(modifier = Modifier.fillMaxSize().background(Color.White)) {
        Head(
            left = { HeadLeft() },
            right = {
                HeadRight(
                    role = { "管家" },
                    click = { println("heiheihei") }
                )
            }
        )

        Spacer(
            modifier = Modifier.fillMaxWidth().height(1.dp).background(Color(0xFFEFF0F1))
        )
        Column(
            modifier = Modifier
                .fillMaxHeight()
                .background(Color.White)
                .padding(horizontal = 50.dp, vertical = 50.dp)
        ) {

            Row(
                modifier = Modifier.fillMaxWidth(),
                horizontalArrangement = Arrangement.SpaceBetween,
                verticalAlignment = Alignment.CenterVertically
            ) {
                Text(
                    text = "全部项目任务",
                    fontSize = 16.sp,
                    fontWeight = FontWeight.Bold,
                    color = Color(0xFF1F2429),
                    modifier = Modifier.height(20.dp)
                )

                BasicTextField(
                    value = value,
                    onValueChange = { value = it },
                    singleLine = true,
                    cursorBrush = SolidColor(Color(0xFFE4E6E7)),
                    modifier = Modifier
                        .width(186.dp)
                        .height(32.dp)
                        .background(Color.White)
                        .border(BorderStroke(1.dp, Color(0xFFE4E6E7)), RoundedCornerShape(4.dp)),
                ) { innerTextField: @Composable () -> Unit ->
                    Row(
                        modifier = Modifier.fillMaxSize(),
                        verticalAlignment = Alignment.CenterVertically) {
                        Spacer(modifier = Modifier.width(8.dp))
                        Icon(
                            imageVector = Icons.Default.Search,
                            contentDescription = "",
                            tint = Color(0xFFE4E6E7),
                            modifier = Modifier.size(16.dp)
                        )
                        Spacer(modifier = Modifier.width(8.dp))
                        innerTextField()
                    }
                }
            }

            Spacer(modifier = Modifier.height(20.dp))

            ProjectRecentTaskTitle()

            LazyColumn(modifier = Modifier.fillMaxWidth().height(436.dp)) {
                items(20) {
                    Box {
                        ProjectRecentTaskItem()
                        Spacer(
                            modifier = Modifier
                                .align(Alignment.BottomCenter)
                                .fillMaxWidth().height(1.dp)
                                .background(Color(0xFFE4E6E7))
                        )
                    }
                }
            }
        }
    }
}


@Preview(widthDp = 1137, heightDp = 711)
@Composable
fun PreviewProjectTaskScreen() {
    ProjectTaskScreen()
}
