package com.example.kmptpc_compose_sample.demos.foundation

import androidx.compose.foundation.layout.*
import androidx.compose.material.Card
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.InternalComposeApi
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalInterfaceOrientation
import androidx.compose.ui.platform.LocalSafeArea
import androidx.compose.ui.unit.dp

@OptIn(InternalComposeApi::class, ExperimentalComposeUiApi::class)
@Composable
internal actual fun OrientationAndSafeAreaDemoContent() {
    val orientation = LocalInterfaceOrientation.current
    val safeArea = LocalSafeArea.current

    Column(
        modifier = Modifier.fillMaxWidth(),
        verticalArrangement = Arrangement.spacedBy(12.dp)
    ) {
        // 1. 界面方向
        Card(
            modifier = Modifier.fillMaxWidth(),
            backgroundColor = MaterialTheme.colors.surface,
            elevation = 2.dp
        ) {
            Column(Modifier.padding(16.dp)) {
                Text(
                    text = "1. 界面方向 (LocalInterfaceOrientation)",
                    style = MaterialTheme.typography.subtitle1
                )
                Spacer(modifier = Modifier.height(8.dp))
                Text(
                    text = "当前方向: $orientation",
                    style = MaterialTheme.typography.body1
                )
                Text(
                    text = "旋转设备/模拟器可观察变化（Portrait / LandscapeLeft / LandscapeRight 等）",
                    style = MaterialTheme.typography.caption,
                    color = MaterialTheme.colors.onSurface.copy(alpha = 0.7f)
                )
            }
        }

        // 2. 系统安全区（系统栏 avoid area）
        Card(
            modifier = Modifier.fillMaxWidth(),
            backgroundColor = MaterialTheme.colors.surface,
            elevation = 2.dp
        ) {
            Column(Modifier.padding(16.dp)) {
                Text(
                    text = "2. 系统安全区 (LocalSafeArea)",
                    style = MaterialTheme.typography.subtitle1
                )
                Spacer(modifier = Modifier.height(8.dp))
                Text(
                    text = "left = ${safeArea.left}",
                    style = MaterialTheme.typography.body2
                )
                Text(
                    text = "top = ${safeArea.top}",
                    style = MaterialTheme.typography.body2
                )
                Text(
                    text = "right = ${safeArea.right}",
                    style = MaterialTheme.typography.body2
                )
                Text(
                    text = "bottom = ${safeArea.bottom}",
                    style = MaterialTheme.typography.body2
                )
                Spacer(modifier = Modifier.height(4.dp))
                Text(
                    text = "对应状态栏/刘海/导航条等占位，单位 dp。与日志 WindowStageManager systemAvoidArea (dp) 一致。",
                    style = MaterialTheme.typography.caption,
                    color = MaterialTheme.colors.onSurface.copy(alpha = 0.7f)
                )
            }
        }
    }
}
