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

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
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 androidx.constraintlayout.compose.ConstraintLayout
import com.google.accompanist.insets.statusBarsHeight
import com.ys.bdtp.adm.R
import com.ys.bdtp.adm.app.theme.textBlackColor

/**
 * 登录页侧边
 */
@Composable
fun LoginSide() {
    ConstraintLayout(modifier = Modifier.fillMaxWidth()) {
        val (statusBar, logo, background, title) = createRefs()

        Image(
            painter = painterResource(R.drawable.login_background),
            contentDescription = "",
            modifier = Modifier.fillMaxSize().constrainAs(background) {
                top.linkTo(parent.top)
                bottom.linkTo(parent.bottom)
                start.linkTo(parent.start)
                end.linkTo(parent.end)
            },
            contentScale = ContentScale.Crop
        )

        Spacer(Modifier.statusBarsHeight().fillMaxWidth().constrainAs(statusBar) {
            top.linkTo(parent.top)
            start.linkTo(parent.start)
            end.linkTo(parent.end)
        })

        Image(
            painter = painterResource(R.drawable.logo),
            contentDescription = "",
            modifier = Modifier.size(112.dp, 48.dp).constrainAs(logo) {
                top.linkTo(statusBar.bottom, margin = 12.dp)
                start.linkTo(parent.start, margin = 32.dp)
            }
        )
        val guideline = createGuidelineFromBottom(0.1f)
        Column(modifier = Modifier.constrainAs(title) {
            top.linkTo(parent.top, margin = 32.dp)
            start.linkTo(parent.start)
            end.linkTo(parent.end)
            bottom.linkTo(guideline)
        }) {
            Text(text = "Yushu", fontSize = 36.sp, color = textBlackColor)
            Text("智慧建筑运维平台", fontSize = 48.sp, color = textBlackColor)
        }
    }
}

@Preview
@Composable
fun PreviewLoginSide() {
    LoginSide()
}