package com.ys.bdtp.adm.mvvm.ui.compose

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
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.layout.wrapContentHeight
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.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.google.accompanist.insets.LocalWindowInsets
import com.google.accompanist.insets.rememberInsetsPaddingValues

@Composable
fun Head(
    modifier: Modifier = Modifier.fillMaxWidth()
        .wrapContentHeight()
        .background(Color.White)
        .padding(
            rememberInsetsPaddingValues(
                LocalWindowInsets.current.statusBars
            )
        ),
    left: (@Composable () -> Unit)? = null,
    middle: (@Composable () -> Unit)? = null,
    right: (@Composable () -> Unit)? = null
) {
    Box(
        modifier = modifier
    ) {
        Row(
            modifier = Modifier
                .height(56.dp)
                .fillMaxWidth(),
            horizontalArrangement = Arrangement.SpaceBetween,
            verticalAlignment = Alignment.CenterVertically
        ) {
            // left
            left?.invoke()

            // middle
            middle?.invoke()

            // right
            right?.invoke()

        }
    }
}

@Preview(widthDp = 1280, heightDp = 800)
@Composable
fun PreviewTop() {
    Head(
        left = { HeadLeft() },
        right = {
            HeadRight(
                role = { "管家" },
                click = { println("heiheihei") }
            )
        }
    )
}

@Preview(widthDp = 1280, heightDp = 800)
@Composable
fun PreviewTop1() {
    Head(
        left = {
            Row(
                verticalAlignment = Alignment.CenterVertically,
                horizontalArrangement = Arrangement.End
            ) {
                Spacer(modifier = Modifier.width(32.dp))
                Text(text = "禹数数字化交付工具", fontSize = 16.sp, fontWeight = FontWeight.Bold, color = Color(0xFF1F2329))
            }
        },
        right = {
            HeadRight(
                role = { "管家" },
                click = { println("heiheihei") }
            )
        }
    )
}