package com.isidroid.c23.ui.screen.details.component

import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBars
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.isidroid.c23.R
import com.isidroid.c23.ui.screen.details.JobDetailsContract


@OptIn(ExperimentalMaterial3Api::class)
@Composable
internal fun DisplayMapRouteConfirmation(
    state: State<JobDetailsContract.State>,
    onEventSent: (event: JobDetailsContract.Event) -> Unit
) {
    if (!state.value.routeConfirmationVisible) return
    val sheetState = rememberModalBottomSheetState()

    ModalBottomSheet(
        onDismissRequest = { onEventSent(JobDetailsContract.Event.DismissBuildRouteConfirmation) },
        sheetState = sheetState,
        windowInsets = WindowInsets.statusBars,
        modifier = Modifier
            .fillMaxWidth()
            .padding(bottom = 120.dp),
    ) {
        Text(
            text = stringResource(id = R.string.app_navigation_explanation),
            modifier = Modifier.padding(horizontal = 16.dp),
            textAlign = TextAlign.Center
        )

        TextButton(
            onClick = { onEventSent(JobDetailsContract.Event.OpenNavigationApp) },
            modifier = Modifier
                .fillMaxWidth()
                .padding(horizontal = 12.dp, vertical = 18.dp)
        ) {
            Text(
                text = "Open in Google Maps",
            )
        }
    }
}