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

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.ys.bdtp.adm.app.theme.bgBlueColor
import com.ys.bdtp.adm.app.theme.underColor
import com.ys.bdtp.adm.app.theme.whiteColor
import com.ys.bdtp.adm.mvvm.model.vo.request.requestBody
import com.ys.bdtp.adm.mvvm.vm.offline.OfflineViewModel
import org.kodein.di.compose.rememberViewModel


/**
 * 离线数据左侧UI
 */
@Composable
fun OfflineSide2() {
    val vm by rememberViewModel<OfflineViewModel>()
    val scope = rememberCoroutineScope()
    Column(
        modifier = Modifier
            .width(280.dp)
            .fillMaxHeight()
            .background(underColor)
            .padding(vertical = 30.dp),
        horizontalAlignment = Alignment.CenterHorizontally
    ) {

        Button(
            modifier = Modifier.size(220.dp, 42.dp),
            onClick = {
                //scope.launch {
                /* vm.getDict(
                     body = requestBody(

                     ),
                     success = {
                         println("success: $it")
                     },
                     failure = {
                         println("failure: $it")
                     }
                 )*/
                //}
            },
            colors = ButtonDefaults.buttonColors(
                contentColor = whiteColor,
                backgroundColor = bgBlueColor
            ),
            elevation = ButtonDefaults.elevation(0.dp)
        ) {
            Text(text = "全部同步")
        }

        Spacer(modifier = Modifier.height(32.dp))
        Button(
            modifier = Modifier.size(220.dp, 42.dp),
            onClick = {
                vm.getDict(
                    body = requestBody(
                        userId = "17337681032",
                        groupCode = "JDKJ",
                        projectId = "Pj1101080665",
                    ),
                    success = {
                        println("success: $it")
                    },
                    failure = {
                        println("failure: $it")
                    }
                )
            },
            colors = ButtonDefaults.buttonColors(
                contentColor = whiteColor,
                backgroundColor = bgBlueColor
            ),
            elevation = ButtonDefaults.elevation(0.dp)
        ) {
            Text(text = "字典数据")
        }
        Spacer(modifier = Modifier.height(32.dp))
        Button(
            modifier = Modifier.size(220.dp, 42.dp),
            onClick = {
                vm.getConfig(
                    body = requestBody(
                        userId = "17337681032",
                        groupCode = "JDKJ",
                        projectId = "Pj1101080665",
                    ),
                    success = {
                        println("success: $it")
                    },
                    failure = {
                        println("failure: $it")
                    }
                )
            },
            colors = ButtonDefaults.buttonColors(
                contentColor = whiteColor,
                backgroundColor = bgBlueColor
            ),
            elevation = ButtonDefaults.elevation(0.dp)
        ) {
            Text(text = "配置数据")
        }
        Spacer(modifier = Modifier.height(32.dp))
        Button(
            modifier = Modifier.size(220.dp, 42.dp),
            onClick = {
                vm.getBuildingsAndFloors(
                    body = requestBody(
                        userId = "17337681032",
                        groupCode = "JDKJ",
                        projectId = "Pj1101080665",
                    ),
                    success = {
                        println("success: $it")
                    },
                    failure = {
                        println("failure: $it")
                    }
                )
            },
            colors = ButtonDefaults.buttonColors(
                contentColor = whiteColor,
                backgroundColor = bgBlueColor
            ),
            elevation = ButtonDefaults.elevation(0.dp)
        ) {
            Text(text = "获取建筑与楼层数据")
        }
        Spacer(modifier = Modifier.height(32.dp))
        Button(
            modifier = Modifier.size(220.dp, 42.dp),
            onClick = {
                vm.getMission(
                    body = requestBody(
                        userId = "17337681032",
                        groupCode = "JDKJ",
                        projectId = "Pj1101080665",
                        buildingId = "Bd990999000204fb9e7d54f54f43a0280b616623d91e"
                    ),
                    success = {
                        println("success: $it")
                    },
                    failure = {
                        println("failure: $it")
                    }
                )
            },
            colors = ButtonDefaults.buttonColors(
                contentColor = whiteColor,
                backgroundColor = bgBlueColor
            ),
            elevation = ButtonDefaults.elevation(0.dp)
        ) {
            Text(text = "任务数据")
        }
    }
}


@Preview
@Composable
fun PreviewOfflineSide2() {
    OfflineSide2()
}