package eu.darken.sdmse.common.compose.layout

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.RowScope
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.twotone.ArrowBack
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import eu.darken.sdmse.common.R as CommonR
import eu.darken.sdmse.common.compose.preview.Preview2
import eu.darken.sdmse.common.compose.preview.PreviewWrapper

@Composable
fun SdmTopAppBar(
    title: String,
    modifier: Modifier = Modifier,
    subtitle: String? = null,
    onNavigateUp: (() -> Unit)? = null,
    actions: @Composable RowScope.() -> Unit = {},
) {
    TopAppBar(
        modifier = modifier,
        title = {
            Column {
                Text(title)
                if (subtitle != null) {
                    Text(
                        text = subtitle,
                        style = MaterialTheme.typography.labelMedium,
                    )
                }
            }
        },
        navigationIcon = {
            if (onNavigateUp != null) {
                SdmTooltipIconButton(
                    icon = Icons.AutoMirrored.TwoTone.ArrowBack,
                    label = stringResource(CommonR.string.general_navigate_up_action),
                    onClick = onNavigateUp,
                )
            }
        },
        actions = actions,
    )
}

@Preview2
@Composable
private fun SdmTopAppBarPreview() {
    PreviewWrapper {
        SdmTopAppBar(
            title = "AppCleaner",
            subtitle = "12 apps scanned",
            onNavigateUp = {},
        )
    }
}
