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

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text
import androidx.compose.material.TextButton
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.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog

@Composable
fun Alert() {
    var flag by remember { mutableStateOf(true) }
    if (flag) {
        Dialog(
            onDismissRequest = { flag = false }
        ) {
            Column(
                modifier = Modifier
                    .width(295.dp)
                    .background(Color.White, shape = RoundedCornerShape(8.dp)),
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                Spacer(
                    modifier = Modifier.height(24.dp)
                )
                Text(
                    text = "数据更新提示",
                    color = Color(0xFF1F2529),
                    fontSize = 18.sp,
                )
                Spacer(
                    modifier = Modifier.height(10.dp)
                )
                Text(
                    text = "离线数据下载同步更新完成",
                    color = Color(0xFF1F2529),
                    fontSize = 14.sp,
                )
                Spacer(
                    modifier = Modifier.height(30.dp)
                )

                Spacer(
                    modifier = Modifier
                        .fillMaxWidth()
                        .height(1.dp)
                        .background(Color(0xFFEFF0F1))
                )
                TextButton(
                    onClick = { flag = !flag },
                    modifier = Modifier.fillMaxWidth().height(50.dp),
                    shape = RoundedCornerShape(
                        topStart = 0.dp,
                        topEnd = 0.dp,
                        bottomStart = 4.dp,
                        bottomEnd = 4.dp
                    )
                ) {
                    Text(
                        text = "我知道了",
                        color = Color(0xFF0091FF),
                        fontSize = 16.sp,
                    )
                }

            }
        }
    }
}


@Preview
@Composable
fun PreviewAlert() {
    Alert()
}