package com.example.kmptpc_compose_sample.demos.foundation

import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.input.TextFieldState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Divider
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

@Composable
internal fun FoundationBasicTextFieldDemo() {
    Column(
        modifier = Modifier
            .fillMaxSize()
            .verticalScroll(rememberScrollState())
            .padding(16.dp),
        verticalArrangement = Arrangement.spacedBy(16.dp)
    ) {
        Text("BasicTextField (Legacy)", style = MaterialTheme.typography.h6)
        var legacyText by remember { mutableStateOf("Legacy BasicTextField content") }
        BasicTextField(
            value = legacyText,
            onValueChange = { legacyText = it },
            modifier = Modifier
                .fillMaxWidth()
                .border(1.dp, Color.Gray, RoundedCornerShape(4.dp))
                .padding(8.dp)
        )

        Divider()

        Text("BasicTextField (New / BTF2)", style = MaterialTheme.typography.h6)
        val btf2State = remember { TextFieldState("New BasicTextField (TextFieldState) content") }
        BasicTextField(
            state = btf2State,
            modifier = Modifier
                .fillMaxWidth()
                .border(1.dp, Color.Blue, RoundedCornerShape(4.dp))
                .padding(8.dp)
        )

        Text("BTF2 State Value: ${btf2State.text}", style = MaterialTheme.typography.caption)

        Divider()

        Text("Multi-line BTF2", style = MaterialTheme.typography.h6)
        val multiLineState = remember { 
            TextFieldState("Line 1\nLine 2\nLine 3\nLong text to test scrolling and selection handles in a multi-line environment on HarmonyOS.") 
        }
        BasicTextField(
            state = multiLineState,
            modifier = Modifier
                .fillMaxWidth()
                .heightIn(min = 100.dp)
                .border(1.dp, Color.Magenta, RoundedCornerShape(4.dp))
                .padding(8.dp)
        )
    }
}
