package com.rosetta.messenger.ui.chats

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.rosetta.messenger.R
import com.rosetta.messenger.ui.onboarding.PrimaryBlue
import com.rosetta.messenger.ui.onboarding.PrimaryBlueDark
import compose.icons.TablerIcons
import compose.icons.tablericons.Phone
import compose.icons.tablericons.Scan
import compose.icons.tablericons.Users

@Composable
fun ColumnScope.DrawerContent(
    isDarkTheme: Boolean,
    visibleTopLevelRequestsCount: Int,
    onProfileClick: () -> Unit,
    onRequestsClick: () -> Unit,
    onCallsClick: () -> Unit,
    onNewGroupClick: () -> Unit,
    onQrScanClick: () -> Unit,
    onSavedMessagesClick: () -> Unit,
    onSettingsClick: () -> Unit
) {
    Column(
        modifier =
            Modifier.fillMaxWidth()
                .weight(1f)
                .verticalScroll(rememberScrollState())
                .padding(vertical = 8.dp)
    ) {
        val menuIconColor = if (isDarkTheme) Color(0xFF828282) else Color(0xFF889198)
        val menuTextColor =
            if (isDarkTheme) Color(0xFFF4FFFFFF.toInt()) else Color(0xFF444444.toInt())
        val accentColor = if (isDarkTheme) PrimaryBlueDark else PrimaryBlue

        DrawerMenuItemEnhanced(
            painter = painterResource(id = R.drawable.left_status_profile),
            text = "My Profile",
            iconColor = menuIconColor,
            textColor = menuTextColor,
            onClick = onProfileClick
        )

        DrawerMenuItemEnhanced(
            painter = painterResource(id = R.drawable.msg_archive),
            text = "Requests",
            iconColor = menuIconColor,
            textColor = menuTextColor,
            badge = if (visibleTopLevelRequestsCount > 0) visibleTopLevelRequestsCount.toString() else null,
            badgeColor = accentColor,
            onClick = onRequestsClick
        )

        DrawerMenuItemEnhanced(
            icon = TablerIcons.Phone,
            text = "Calls",
            iconColor = menuIconColor,
            textColor = menuTextColor,
            onClick = onCallsClick
        )

        DrawerMenuItemEnhanced(
            icon = TablerIcons.Users,
            text = "New Group",
            iconColor = menuIconColor,
            textColor = menuTextColor,
            onClick = onNewGroupClick
        )

        DrawerMenuItemEnhanced(
            icon = TablerIcons.Scan,
            text = "Scan QR",
            iconColor = menuIconColor,
            textColor = menuTextColor,
            onClick = onQrScanClick
        )

        DrawerMenuItemEnhanced(
            painter = painterResource(id = R.drawable.msg_saved),
            text = "Saved Messages",
            iconColor = menuIconColor,
            textColor = menuTextColor,
            onClick = onSavedMessagesClick
        )

        DrawerDivider(isDarkTheme)

        DrawerMenuItemEnhanced(
            painter = painterResource(id = R.drawable.msg_settings_old),
            text = "Settings",
            iconColor = menuIconColor,
            textColor = menuTextColor,
            onClick = onSettingsClick
        )

        Spacer(modifier = Modifier.height(8.dp))
    }
}
