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

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
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 FullScreenView(
    showPopup: MutableState<Boolean> = mutableStateOf(false),
    contentAlignment: Alignment = Alignment.Center,
    backgroundColor: Color = Color.Black.copy(alpha = 0.66f),
    content: @Composable () -> Unit = {},
) {
    if (showPopup.value) {
        // full screen background
        Box(
            modifier = Modifier
                .fillMaxSize()
                .background(backgroundColor)
        ) {
            // 팝업 윈도 외부 키 입력 방지를 위해 한번더 전체 화면으로 박스를 만듬.
            Box( modifier = Modifier
                .fillMaxSize()
                .pointerInput(Unit) {
                    // 터치나 클릭 이벤트가 하위 뷰로 전달 되는 것을 방지
                    // 아니면, 아래 뷰도 같이 동작 하는 문제 발생.
                    awaitPointerEventScope {
                        while (true) {
                            awaitPointerEvent() // Consume the event
                        }
                    }
                },
                contentAlignment = contentAlignment
            ) {
                content()
            }
        }
    }
}

