package com.dong.maxhap.demos.foundation

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Slider
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
internal fun FoundationLazyColumnDemo() {
    var count by remember { mutableStateOf(10) }
    var spaced by remember { mutableStateOf(4) }

    Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
        Text("条目数量: $count")
        Slider(value = count.toFloat(), onValueChange = { count = it.toInt() }, valueRange = 1f..50f)
        Text("条目间距: ${spaced}dp")
        Slider(value = spaced.toFloat(), onValueChange = { spaced = it.toInt() }, valueRange = 0f..24f)

        LazyColumn(
            modifier = Modifier
                .fillMaxWidth()
                .height(220.dp)
                .background(MaterialTheme.colors.surface),
            contentPadding = PaddingValues(8.dp),
            verticalArrangement = Arrangement.spacedBy(spaced.dp)
        ) {
            items((1..count).toList()) { idx ->
                Box(
                    modifier = Modifier
                        .fillMaxWidth()
                        .height(40.dp)
                        .background(MaterialTheme.colors.secondary),
                    contentAlignment = Alignment.Center
                ) {
                    Text("Item #$idx")
                }
            }
        }
    }
}
