package llc.arma.ble.app.ui.screen.inspection.beacon.view

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.KeyboardArrowDown
import androidx.compose.material.icons.rounded.KeyboardArrowRight
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import llc.arma.ble.app.ui.model.BleView
import llc.arma.ble.app.ui.screen.BleInfoView
import llc.arma.ble.app.ui.screen.inspection.beacon.BeaconContract
import llc.arma.ble.domain.model.Ble

@Composable
fun DisplayState(
    onEvent: (BeaconContract.Event) -> Unit,
    origin: Ble.Beacon,
    ble: BleView.Beacon
) {

    Column() {

        Column(
            modifier = Modifier
                .verticalScroll(rememberScrollState())
                .weight(1f)
        ) {

            Box(
                modifier = Modifier.padding(
                    vertical = 8.dp,
                    horizontal = 8.dp
                )
            ) {
                BleInfoView(bleInfo = origin.info)
            }

            Column(
                modifier = Modifier,
                content = {

                    Box(
                        modifier = Modifier.padding(
                            vertical = 8.dp,
                            horizontal = 8.dp
                        )
                    ) {

                        Row(
                            verticalAlignment = Alignment.CenterVertically,
                            modifier = Modifier
                                .clip(RoundedCornerShape(16.dp))
                                .clickable {
                                    onEvent(BeaconContract.Event.OnPowerEdit)
                                }
                                .padding(8.dp)
                        ) {

                            Column(
                                modifier = Modifier.weight(1f)
                            ) {

                                Text(
                                    text = "Мощность"
                                )
                                Text(
                                    color = MaterialTheme.colorScheme.secondary,
                                    style = MaterialTheme.typography.bodyMedium,
                                    text = "${ble.state.tx.value} db"
                                )

                            }

                            Icon(
                                imageVector = Icons.Rounded.KeyboardArrowDown,
                                contentDescription = null
                            )

                        }

                    }

                    Box(
                        modifier = Modifier.padding(
                            vertical = 8.dp,
                            horizontal = 8.dp
                        )
                    ) {

                        Row(
                            verticalAlignment = Alignment.CenterVertically,
                            modifier = Modifier
                                .clip(RoundedCornerShape(16.dp))
                                .clickable {
                                    onEvent(BeaconContract.Event.OnChangePassword)
                                }
                                .padding(8.dp)
                        ) {

                            Column(
                                modifier = Modifier.weight(1f)
                            ) {

                                Text(
                                    text = "Изменить пароль"
                                )

                            }

                            Icon(
                                imageVector = Icons.Rounded.KeyboardArrowRight,
                                contentDescription = null
                            )

                        }

                    }

                }
            )

        }

        Surface(
            modifier = Modifier
                .fillMaxWidth()
                .padding(8.dp)
                .height(50.dp),
            shape = CircleShape,
            color = MaterialTheme.colorScheme.primaryContainer,
            onClick = {
                onEvent(BeaconContract.Event.OnShowWriteBlePreview)
            }
        ) {

            Box(modifier = Modifier.fillMaxSize()) {

                Text(
                    modifier = Modifier.align(Alignment.Center),
                    color = MaterialTheme.colorScheme.background,
                    style = MaterialTheme.typography.labelLarge,
                    text = "Сохранить"
                )

            }

        }

    }

}