package com.laseroptek.raman.ui.screens.home.dcd

import android.content.res.Configuration
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.laseroptek.raman.data.datasource.db.RamanDatabase
import com.laseroptek.raman.data.source.db.RamanDatabaseService
import com.laseroptek.raman.repository.DatabaseRepository
import com.laseroptek.raman.repository.PreferenceRepository
import com.laseroptek.raman.repository.SerialPortRepository
import com.laseroptek.raman.ui.screens.main.MainViewModel
import com.laseroptek.raman.utils.DefaultDispatcherProvider


@Composable
fun VerticallyRotatedCharacters(
    text: String = "",
    modifier: Modifier = Modifier,
    charStyle: TextStyle = TextStyle.Default.copy(fontSize = 8.sp)
) {
    Column(
        modifier = modifier,
        horizontalAlignment = Alignment.CenterHorizontally, // How the column aligns its children (each Text)
        verticalArrangement = Arrangement.spacedBy(-4.dp) // Optional: space between rotated characters
    ) {
        text.forEach { char ->
            Text(
                text = char.toString(),
                style = charStyle,
                modifier = Modifier
                    .rotate(90f) // Rotate each character 90 degrees clockwise
                    .padding(horizontal = 0.dp) // Add some padding so chars don't touch if wide
            )
        }
    }
}



@Preview(
    apiLevel = 34,
    uiMode = Configuration.UI_MODE_NIGHT_NO,
    showBackground = false,
    device = "spec:width=1920dp,height=1080dp,dpi=150,isRound=false,chinSize=0dp,orientation=landscape"
)
@Composable
fun VerticallyRotatedCharactersPreview(
    mainViewModel:MainViewModel = MainViewModel(
        preferenceRepository = PreferenceRepository(LocalContext.current),
        serialPortRepository = SerialPortRepository.createWithFakeRepository(),
        databaseRepository = DatabaseRepository(RamanDatabaseService(RamanDatabase.getInstance(LocalContext.current))),
        dispatcherProvider = DefaultDispatcherProvider(),
        applicationContext = LocalContext.current
    )
) {
    VerticallyRotatedCharacters(
        //mainViewModel = mainViewModel
        text = "COOLER TITLE"
    )
}
