package com.suno.android.ui.screens.orpheus import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.Crossfade import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material3.CenterAlignedTopAppBar import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.suno.android.common_core_utils.environment.ThemeMode import com.suno.android.common_ui.components.omni.CircleIconButton import com.suno.android.common_ui.extensions.xAsFormattedCount import com.suno.android.common_ui.theme.ExtendedTheme import com.suno.android.common_ui.theme.SunoTheme import com.suno.android.common_res.R as CommonResR import com.suno.android.common_ui.R as CommonUIR @Composable internal fun OrpheusChatTopBar( chatState: OrpheusChatState, onBackClick: () -> Unit, onNewChatClick: () -> Unit, onWorkspacesClick: () -> Unit, ) { SunoTheme( themeMode = if (chatState.isEmptyState) ThemeMode.DARK else ThemeMode.SYSTEM, ) { val color = if (chatState.isEmptyState) Color.Transparent else ExtendedTheme.colors.backgroundPrimary CenterAlignedTopAppBar( colors = TopAppBarDefaults.topAppBarColors( containerColor = color, scrolledContainerColor = color, ), navigationIcon = { CircleIconButton( modifier = Modifier.padding(horizontal = 8.dp), vectorDrawableResId = CommonUIR.drawable.arrow_left, contentDescription = stringResource(CommonResR.string.close), onClick = onBackClick, bgColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.1f), ) }, title = { Column(horizontalAlignment = Alignment.CenterHorizontally) { val titleText = chatState.currentProject?.name ?: stringResource(CommonResR.string.orpheus_chat_title) Crossfade(targetState = titleText) { text -> Text( modifier = Modifier.fillMaxWidth(), text = text, style = ExtendedTheme.typography.mediumTitle, textAlign = TextAlign.Center, maxLines = 1, overflow = TextOverflow.Ellipsis, ) } val creditCount = chatState.creditCount val modelName = chatState.selectedModel?.name AnimatedVisibility(visible = creditCount != null && modelName != null) { if (creditCount != null && modelName != null) { Text( text = stringResource( CommonResR.string.orpheus_chat_subtitle, creditCount.xAsFormattedCount(), modelName, ), style = ExtendedTheme.typography.smallSubtitle.copy( color = ExtendedTheme.colors.textTertiary, ), ) } } } }, actions = { Box( modifier = Modifier.padding(horizontal = 8.dp), ) { when { chatState.isProjectsEnabled -> CircleIconButton( vectorDrawableResId = CommonUIR.drawable.workspace, contentDescription = stringResource(CommonResR.string.orpheus_show_workspaces), onClick = onWorkspacesClick, modifier = Modifier.graphicsLayer { scaleX = -1f // flip drawer icon since android drawer is on the right }, bgColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.1f), ) !chatState.messages.dataOrNull.isNullOrEmpty() -> CircleIconButton( vectorDrawableResId = CommonUIR.drawable.compose, contentDescription = stringResource(CommonResR.string.orpheus_new_chat), onClick = onNewChatClick, bgColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.1f), ) } } }, ) } }