package llc.arma.ble.app.ui.screen.rotation.delete

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

@Composable
fun RotationDeleteScreen(
    onNavigation: (RotationDeleteContract.Effect.Navigation) -> Unit
) {

    val viewModel = hiltViewModel<RotationDeleteViewModel>()

    LaunchedEffect(Unit) {
        viewModel.effect.onEach {
            when(it){
                is RotationDeleteContract.Effect.Navigation -> onNavigation(it)
            }
        }.launchIn(this)
    }

    Surface(
        shape = RoundedCornerShape(16.dp)
    ) {

        Column(
            modifier = Modifier.padding(16.dp)
        ) {

            Text(
                style = MaterialTheme.typography.titleLarge,
                text = "Удалить сохраненные записи?"
            )


            Row(
                horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End),
                modifier = Modifier
                    .align(Alignment.End)
            ) {

                TextButton(
                    onClick = {
                        viewModel.setEvent(
                            RotationDeleteContract.Event.OnNavigateUp
                        )
                    }
                ) {
                    Text(text = "Отмена")
                }

                Button(
                    onClick = {
                        viewModel.setEvent(
                            RotationDeleteContract.Event.OnDelete
                        )
                    }
                ) {
                    Text(text = "Удалить")
                }

            }

        }

    }

}
