package com.example.wabi.view.common_elements.textfields

import androidx.compose.foundation.border
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import com.example.wabi.ui.theme.WabiTheme

//поле для кода
@Composable
fun CodeTextField(
    value: String,
    input: (String) -> Unit,
) {
    OutlinedTextField(
        value = value,
        onValueChange = {
            if (it.length == 2 && it.isNotEmpty()) input(it.substring(1))
            else input(it)
        },
        singleLine = true,
        shape = RoundedCornerShape(
            40.dp
        ),
        modifier = Modifier
            .width(55.dp)
            .height(55.dp)
            .border(
                width = 2.dp, color = WabiTheme.colors.mainColor, shape = RoundedCornerShape(
                    40.dp
                )
            ),
        textStyle = WabiTheme.fonts.code,
        colors = TextFieldDefaults.colors(
            unfocusedContainerColor = WabiTheme.colors.backgroundColor,
            focusedContainerColor = WabiTheme.colors.backgroundColor,
            unfocusedTextColor = WabiTheme.colors.mainColor,
            focusedTextColor = WabiTheme.colors.mainColor,
            cursorColor = WabiTheme.colors.mainColor
        ),
        keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword),
    )
}