package solutions.tretter.mindmachine.session

import androidx.compose.foundation.layout.*
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import kotlin.math.roundToInt

/**
 * Temporary parameter controls (sliders) to keep SetupScreen functional.
 *
 * The full timeline editor per spec is implemented separately in TimelineEditorScreen.
 */

@Composable
fun TimelineParameterControl(
    model: TimelineModel,
    onParameterChanged: (String, Float) -> Unit,
    modifier: Modifier = Modifier,
    showTimeline: Boolean = false,
    onTimelineChanged: (Int) -> Unit = {}
) {
    Column(
        modifier = modifier,
        verticalArrangement = Arrangement.spacedBy(12.dp)
    ) {
        Text(
            model.preset.name,
            style = MaterialTheme.typography.headlineSmall,
            color = MaterialTheme.colorScheme.onBackground
        )

        model.parameters.forEach { p ->
            Row(
                Modifier.fillMaxWidth(),
                verticalAlignment = Alignment.CenterVertically,
                horizontalArrangement = Arrangement.SpaceBetween
            ) {
                Column(Modifier.weight(1f)) {
                    Text(p.name, color = MaterialTheme.colorScheme.onBackground)
                    Text(p.description, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onBackground)
                }
                Text(
                    when (p.units) {
                        "s" -> String.format("%.2f %s", p.value, p.units)
                        else -> "${p.value.roundToInt()} ${p.units}"
                    },
                    color = MaterialTheme.colorScheme.onBackground
                )
            }
            Slider(
                value = p.value,
                onValueChange = { onParameterChanged(p.id, it) },
                valueRange = p.min..p.max,
                modifier = Modifier.fillMaxWidth()
            )
        }
    }
}
