package com.laseroptek.raman.ui.common.fullscreen

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput

@Composable
fun FullScreen(
    contentAlignment: Alignment = Alignment.Center,
    backgroundColor: Color = Color.Black.copy(alpha = 0.66f),
    content: @Composable () -> Unit = {},
) {
    // full screen background
    Box(
        modifier = Modifier
            .fillMaxSize()
            // Apply the background color to this Box.
            .background(backgroundColor)
            // Add a disabled clickable modifier.
            // This stabilizes the gesture input system and explicitly consumes clicks,
            // preventing them from passing through to elements underneath.
            .clickable(
                enabled = false,
                onClick = {},
                indication = null,
                interactionSource = remember { MutableInteractionSource() }
            )
            // Apply the pointerInput to this SAME Box to intercept all touch events
            // on its surface, preventing them from reaching UI elements underneath.
            .pointerInput(Unit) {
                awaitPointerEventScope {
                    while (true) {
                        // Await and consume the event to stop its propagation.
                        awaitPointerEvent()
                    }
                }
            },
        // The contentAlignment will correctly position the content within this Box.
        contentAlignment = contentAlignment
    ) {
        // Place the content directly inside this single, effective Box.
        content()
    }
}

