package cl.homelogic.platform.designsystem.components.molecules

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import cl.homelogic.platform.designsystem.components.atoms.SimpleCard
import cl.homelogic.platform.designsystem.components.atoms.SymbolText
import cl.homelogic.platform.designsystem.extensions.scaledByFontSize
import cl.homelogic.platform.designsystem.foundations.Dimens
import cl.homelogic.platform.designsystem.foundations.FeedbackType
import cl.homelogic.platform.designsystem.foundations.LocalHapticManager
import cl.homelogic.platform.designsystem.foundations.Padding
import cl.homelogic.platform.designsystem.foundations.Sizes
import cl.homelogic.platform.designsystem.foundations.Symbols

@Composable
fun IconShortcut(
    modifier: Modifier = Modifier,
    icon: Symbols? = null,
    rawIcon: String = "",
    title: String,
    hasNotification: Boolean = false,
    onClick: (() -> Unit)? = null,
) {
    val haptic = LocalHapticManager.current

    SimpleCard(
        onClick = {
            haptic.performFeedback(FeedbackType.SegmentTick)
            onClick?.invoke()
        },
        modifier = modifier,
    ) {
        Box(
            modifier = Modifier
                .fillMaxWidth()
                .height(Sizes.Buttons.Big.scaledByFontSize()),
        ) {
            Row(
                modifier = Modifier
                    .fillMaxSize()
                    .background(MaterialTheme.colorScheme.surfaceContainer)
                    .padding(start = Padding.small),
                verticalAlignment = Alignment.CenterVertically,
            ) {
                icon?.let { SymbolText(icon = icon) } ?: SymbolText(rawIcon = rawIcon)
                Spacer(modifier = Modifier.width(Sizes.Spacers.Regular))
                Text(
                    text = title,
                    style = typography.labelLarge,
                )
            }

            if (hasNotification) {
                Box(
                    modifier = Modifier
                        .fillMaxHeight()
                        .width(Dimens.at8)
                        .align(Alignment.TopEnd)
                        .background(MaterialTheme.colorScheme.tertiary),
                )
            }
        }
    }
}
