package com.prodhack.moscow2025.presentation.components.standart

import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.prodhack.moscow2025.R
import com.prodhack.moscow2025.presentation.theme.Paddings
import com.prodhack.moscow2025.presentation.theme.Shapes
import com.prodhack.moscow2025.presentation.utils.ui.noRippleClickable

@Composable
fun TBubble(
	modifier: Modifier = Modifier,
	text: String,
	isSelected: Boolean = false,
	onDelete: (() -> Unit)? = null
) {
	val shapes = MaterialTheme.shapes
	val typography = MaterialTheme.typography
	val colorScheme = MaterialTheme.colorScheme
	val bubbleColor =
		animateColorAsState(
			if (isSelected) colorScheme.primary else colorScheme.secondary
		)
	val bubbleBorderColor =
		animateColorAsState(
			if (isSelected) colorScheme.primaryFixed else colorScheme.secondaryFixed
		)
	val contentColor =
		animateColorAsState(
			if (isSelected) colorScheme.onPrimary else colorScheme.onSecondary
		)
	Row(
		modifier = modifier
			.background(
				color = bubbleColor.value,
				shape = shapes.small
			)
			.border(
				width = 1.dp,
				color = bubbleBorderColor.value,
				shape = shapes.small
			)
			.clip(Shapes.smallRoundedBox)
			.padding(horizontal = Paddings.small, vertical = Paddings.verySmall),
		verticalAlignment = Alignment.CenterVertically
	) {
		Text(
			text = text,
			style = typography.labelLarge,
			fontSize = 16.sp,
			color = contentColor.value
		)
		onDelete?.let {
			Spacer(modifier = Modifier.width(Paddings.verySmall))
			Icon(
				modifier = Modifier.noRippleClickable(it),
				painter = painterResource(R.drawable.ic_remove),
				tint = contentColor.value,
				contentDescription = "Remove"
			)
		}
	}
}