package com.fabledsword.minstrel.shared.widgets

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

/**
 * Labeled horizontal-scroll section used throughout the Home screen.
 * Mirrors `flutter_client/lib/library/widgets/horizontal_scroll_row.dart`
 * — a Fraunces section title at 16dp gutter, then a horizontal LazyRow
 * with the same gutter and 8dp inter-item spacing.
 *
 * Pass empty `title` to render a continuation row directly under a
 * previously-titled one (used by Rediscover when it has both album and
 * artist sub-rows, and by chunked sections like Recently-added).
 *
 * The `content` lambda receives a `LazyListScope` so callers use
 * `items(list, key = ...) { ... }` — preserves lazy item rendering.
 */
@Composable
fun HorizontalScrollRow(
    title: String,
    modifier: Modifier = Modifier,
    content: LazyListScope.() -> Unit,
) {
    Column(modifier = modifier.fillMaxWidth()) {
        if (title.isNotEmpty()) {
            Text(
                text = title,
                style = MaterialTheme.typography.titleLarge,
                color = MaterialTheme.colorScheme.onBackground,
                modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
            )
        }
        LazyRow(
            contentPadding = PaddingValues(horizontal = 16.dp),
            horizontalArrangement = Arrangement.spacedBy(8.dp),
            content = content,
        )
    }
}
