package com.isidroid.c23.ui.screen.details.component

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

@Composable
fun PrintCodeComponent(
    code: String,
    modifier: Modifier = Modifier
) {
    Row(modifier = modifier) {
        for (c in code)
            PrintCodeElement(c)
    }
}

@Composable
private fun PrintCodeElement(c: Char) {
    Text(
        text = "$c",
        fontSize = 24.sp,
        color = Color.White,
        style = MaterialTheme.typography.displayLarge,
        modifier = Modifier
            .padding(horizontal = 8.dp, vertical = 8.dp)
            .background(Color.Blue, RoundedCornerShape(6.dp))
            .padding(horizontal = 12.dp, vertical = 0.dp)
    )
}

@Preview
@Composable
fun PrintCodeComponentPreview() {
    Surface {
        PrintCodeComponent("7819128")
    }
}