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


import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.GridCells
import androidx.compose.foundation.lazy.LazyVerticalGrid
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
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.app.theme.textBlackColor
import com.ys.bdtp.adm.mvvm.model.db.entity.task.ProjectEntity

@ExperimentalFoundationApi
@Composable
fun ProjectContent(projects: List<ProjectEntity>) {
    Column {
        Text(text = "可进入的项目(${projects.size})", fontSize = 18.sp, fontWeight = FontWeight.Bold, color = textBlackColor)
        Spacer(modifier = Modifier.height(14.dp))
        LazyVerticalGrid(
            cells = GridCells.Fixed(2),
        ) {
            itemsIndexed(projects) { index, item ->
                if (index % 2 == 0)
                    Row(modifier = Modifier.padding(end = 15.dp, bottom = 20.dp)) {
                        ProjectItem(item)
                    }
                else {
                    Row(modifier = Modifier.padding(start = 15.dp, bottom = 20.dp)) {
                        ProjectItem(item)
                    }
                }
            }
        }
    }

}

@OptIn(ExperimentalFoundationApi::class)
@Preview(widthDp = 1137, heightDp = 711)
@Composable
fun PreviewProjectContent() {
    ProjectContent(
        listOf(
            ProjectEntity(
                projectId = "112233",
                projectName = "京东科技大厦",
                groupCode = "JD",
                groupName = "京东"
            ),
            ProjectEntity(
                projectId = "112233",
                projectName = "京东科技大厦",
                groupCode = "JD",
                groupName = "京东"
            ),
            ProjectEntity(
                projectId = "112233",
                projectName = "京东科技大厦",
                groupCode = "JD",
                groupName = "京东"
            ),
            ProjectEntity(
                projectId = "112233",
                projectName = "京东科技大厦",
                groupCode = "JD",
                groupName = "京东"
            ),
            ProjectEntity(
                projectId = "112233",
                projectName = "京东科技大厦",
                groupCode = "JD",
                groupName = "京东"
            )
        )
    )
}

