package com.fabledsword.minstrel.shared.widgets

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier

/**
 * Shared loading-spinner widget for screens that wrap their content in
 * [PullToRefreshScaffold]. Rendered inside a single-item LazyColumn
 * (mirroring [EmptyState]) so the widget participates in nested-scroll
 * dispatch — pull-to-refresh fires on the Loading branch, letting users
 * recover from a stuck cold-load via pull-down instead of having to
 * kill the process.
 *
 * Replaces the per-screen `private fun LoadingCentered()` duplicates
 * that used a bare `Box(fillMaxSize)` and silently swallowed the
 * pull-to-refresh gesture.
 */
@Composable
fun LoadingCentered(modifier: Modifier = Modifier) {
    LazyColumn(modifier = modifier.fillMaxSize()) {
        item {
            Box(
                modifier = Modifier.fillParentMaxSize(),
                contentAlignment = Alignment.Center,
            ) {
                CircularProgressIndicator(color = MaterialTheme.colorScheme.primary)
            }
        }
    }
}
