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

import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import cl.homelogic.platform.designsystem.components.atoms.SymbolText
import cl.homelogic.platform.designsystem.foundations.FeedbackType
import cl.homelogic.platform.designsystem.foundations.LocalHapticManager
import cl.homelogic.platform.designsystem.foundations.Shapes
import cl.homelogic.platform.designsystem.foundations.Sizes
import cl.homelogic.platform.designsystem.foundations.Symbols

@Composable
fun SymbolButton(
    modifier: Modifier = Modifier.size(Sizes.Buttons.Regular),
    icon: Symbols,
    color: Color = MaterialTheme.colorScheme.primary,
    background: Color = Color.Transparent,
    hapticFeedback: Boolean = true,
    onClick: (() -> Unit)? = null,
) {
    val haptic = LocalHapticManager.current
    val interactionSource = remember { MutableInteractionSource() }
    Box(
        modifier = modifier
            .clip(Shapes.RoundCorner.regular)
            .background(background)
            .clickable(
                interactionSource = interactionSource,
                indication = LocalIndication.current,
                onClick = {
                    if (hapticFeedback) haptic.performFeedback(FeedbackType.SegmentTick)
                    onClick?.invoke()
                },
            ),
        contentAlignment = Alignment.Center,
    ) {
        SymbolText(icon = icon, style = typography.displaySmall, color = color)
    }
}
