package com.fabledsword.minstrel.shared.widgets

import androidx.compose.foundation.layout.RowScope
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import com.composables.icons.lucide.ArrowLeft
import com.composables.icons.lucide.Lucide

/**
 * The standard Minstrel top app bar — a `Text(title)` on the left, the
 * universal [MainAppBarActions] row on the right, optionally preceded
 * by extra screen-specific actions and a back arrow.
 *
 * Replaces the TopAppBar + title + navigationIcon + MainAppBarActions
 * sandwich that was duplicated across ~10 screens. Library wraps this
 * in a `Column` with its tab row; drill-down screens pass [onBack]
 * for the back arrow; Library passes its Shuffle button via [actions].
 */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MinstrelTopAppBar(
    title: String,
    navController: NavHostController,
    currentRouteName: String?,
    onBack: (() -> Unit)? = null,
    actions: @Composable RowScope.() -> Unit = {},
) {
    TopAppBar(
        title = { Text(title) },
        navigationIcon = {
            if (onBack != null) {
                IconButton(onClick = onBack) {
                    Icon(Lucide.ArrowLeft, contentDescription = "Back")
                }
            }
        },
        actions = {
            actions()
            MainAppBarActions(
                navController = navController,
                currentRouteName = currentRouteName,
            )
        },
    )
}
