package com.example.smarthome.ui

import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.spring
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.draw.scale
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.withTransform
import androidx.compose.ui.unit.dp

@Composable
fun NeumorphButton(active: Boolean, onToggle: () -> Unit, content: @Composable () -> Unit) {
    val shape = RoundedCornerShape(24.dp)
    val scale by animateFloatAsState(targetValue = if (active) 0.98f else 1f, animationSpec = spring(), label = "scale")
    Row(
        modifier = Modifier
            .scale(scale)
            .background(
                brush = Brush.linearGradient(
                    colors = listOf(Color(0xFF161616), Color(0xFF0E0E0E))
                ),
                shape = shape
            )
            .drawWithCache {
                onDrawWithContent {
                    drawContent()
                    drawRect(
                        brush = Brush.radialGradient(listOf(Color(0x227B61FF), Color.Transparent)),
                        size = size
                    )
                }
            }
            .clickable { onToggle() }
            .padding(PaddingValues(20.dp)),
        verticalAlignment = Alignment.CenterVertically,
        horizontalArrangement = Arrangement.spacedBy(12.dp)
    ) {
        content()
    }
}
