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

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
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.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Text
import androidx.compose.material.TextButton
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.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.google.accompanist.flowlayout.FlowRow
import com.ys.bdtp.adm.app.theme.textBlackColor
import com.ys.bdtp.adm.app.theme.trDivColor
import com.ys.bdtp.adm.mvvm.ui.compose.Table

data class Major(val major: String, val number: Int)

val majors = listOf(
    Major(major = "强电专业", number = 6),
    Major(major = "弱点专业", number = 6),
    Major(major = "空调专业", number = 6),
    Major(major = "给排水专业", number = 6),
    Major(major = "消防专业", number = 6),
    Major(major = "安防专业", number = 6),
    Major(major = "土建精装专业", number = 6),
    Major(major = "电梯专业", number = 6)
)

@Composable
fun CadContent(modifier: Modifier = Modifier) {
    Column(modifier = modifier.background(Color.White)) {
        FlowRow {
            majors.forEach { major ->
                Box(
                    modifier = Modifier
                        .width(150.dp)
                        .height(58.dp)
                        .padding(start = 10.dp, top = 10.dp),
                ) {
                    TextButton(
                        onClick = {},
                        modifier = modifier.width(120.dp).height(28.dp),
                        colors = ButtonDefaults.textButtonColors(
                            backgroundColor = Color(0xFFE1F2FF),
                            contentColor = Color(0xFF0091FF)
                        ),
                        contentPadding = PaddingValues(),
                        shape = RoundedCornerShape(4.dp)
                    ) {
                        Text(text = "${major.major}(${major.number})", fontSize = 14.sp)
                    }
                }
            }
        }
        Spacer(modifier = Modifier.fillMaxWidth().height(40.dp))
        Table(
            name = {
                Text(text = "CAD图纸核查", color = textBlackColor, fontSize = 16.sp)
            },
            th = {
                CadDrawingTitle()
            },
            tr = {
                LazyColumn(modifier = Modifier.fillMaxSize()) {
                    items(20) {
                        Box {
                            CadDrawingItem()
                            Spacer(
                                modifier = Modifier
                                    .align(Alignment.BottomCenter)
                                    .fillMaxWidth().height(1.dp)
                                    .background(trDivColor)
                            )
                        }
                    }
                }
            }
        )
    }
}

@Preview(widthDp = 910, heightDp = 711)
@Composable
fun PreviewCadContent() {
    CadContent()
}