package com.gh.gamecenter.setting.compose.ui.component

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.*
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.gh.gamecenter.setting.compose.R
import com.gh.gamecenter.setting.compose.ui.theme.HaloTheme
import com.gh.gamecenter.setting.compose.ui.theme.backgroundWhiteLight
import com.gh.gamecenter.setting.compose.ui.theme.textTitleLight

@Composable
fun SettingTopAppBar(title: String, onBack: () -> Unit?) {
    TopAppBar(
        modifier = Modifier.height(48.dp),
        elevation = 0.dp,
        backgroundColor = HaloTheme.colors.backgroundWhite
    ) {
        IconButton(
            onClick = { onBack.invoke() },
            modifier = Modifier
                .width(44.dp)
                .padding(end = 4.dp)
        ) {
            Icon(
                imageVector = ImageVector.vectorResource(id = R.drawable.ic_bar_back),
                contentDescription = null,
                tint = if (isSystemInDarkTheme()) backgroundWhiteLight else textTitleLight
            )
        }
        Text(
            text = title,
            fontSize = 16.sp,
            fontWeight = FontWeight.Bold,
            color = HaloTheme.colors.textTitle,
            modifier = Modifier
                .fillMaxWidth()
                .wrapContentSize(Alignment.Center)
                .padding(end = 44.dp)
        )
    }
}