package com.tangem.features.onramp.selecttoken.ui

import androidx.activity.compose.BackHandler
import androidx.annotation.StringRes
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.tangem.core.ui.components.appbar.AppBarWithBackButton
import com.tangem.core.ui.res.TangemTheme
import com.tangem.features.onramp.impl.R
import com.tangem.features.onramp.tokenlist.OnrampTokenListComponent

@OptIn(ExperimentalFoundationApi::class)
@Composable
internal fun OnrampSelectToken(
    @StringRes titleResId: Int,
    onBackClick: () -> Unit,
    onrampTokenListComponent: OnrampTokenListComponent,
    modifier: Modifier = Modifier,
) {
    BackHandler(onBack = onBackClick)

    LazyColumn(
        modifier = modifier
            .background(TangemTheme.colors.background.secondary)
            .imePadding()
            .systemBarsPadding(),
    ) {
        stickyHeader(key = "header") {
            AppBarWithBackButton(
                onBackClick = onBackClick,
                text = stringResource(id = titleResId),
                iconRes = R.drawable.ic_close_24,
                containerColor = TangemTheme.colors.background.secondary,
            )
        }

        item(key = "token_list", contentType = "token_list") {
            onrampTokenListComponent.Content(
                modifier = Modifier.padding(vertical = 8.dp, horizontal = 16.dp),
            )
        }
    }
}