package net.thunderbird.feature.navigation.drawer.dropdown.ui.setting

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import app.k9mail.core.ui.compose.common.window.WindowSizeClass
import app.k9mail.core.ui.compose.common.window.getWindowSizeInfo
import app.k9mail.core.ui.compose.theme2.MainTheme
import net.thunderbird.core.ui.compose.designsystem.atom.icon.Icons
import net.thunderbird.feature.navigation.drawer.dropdown.R

@Composable
internal fun AccountSettingList(
    onAddAccountClick: () -> Unit,
    onSyncAllAccountsClick: () -> Unit,
    onSettingsClick: () -> Unit,
    isLoading: Boolean,
    modifier: Modifier = Modifier,
) {
    val windowSizeInfo = getWindowSizeInfo()
    val isLandscape = windowSizeInfo.screenWidth > windowSizeInfo.screenHeight
    val isCompactHeight = windowSizeInfo.screenHeightSizeClass == WindowSizeClass.Compact
    val hideText = isLandscape && isCompactHeight

    SettingList(
        modifier = modifier
            .padding(vertical = MainTheme.spacings.default)
            .fillMaxWidth(),
    ) {
        item(span = { if (hideText) GridItemSpan(1) else GridItemSpan(maxLineSpan) }) {
            SettingListItem(
                label = stringResource(id = R.string.navigation_drawer_dropdown_action_sync_all_accounts),
                onClick = onSyncAllAccountsClick,
                icon = Icons.Outlined.Sync,
                isLoading = isLoading,
            )
        }
        item(span = { if (hideText) GridItemSpan(1) else GridItemSpan(maxLineSpan) }) {
            SettingListItem(
                label = stringResource(id = R.string.navigation_drawer_dropdown_action_add_account),
                onClick = onAddAccountClick,
                icon = Icons.Outlined.Add,
            )
        }
        item(span = { if (hideText) GridItemSpan(1) else GridItemSpan(maxLineSpan) }) {
            SettingListItem(
                label = stringResource(id = R.string.navigation_drawer_dropdown_action_settings),
                onClick = onSettingsClick,
                icon = Icons.Outlined.Settings,
            )
        }
    }
}
