package com.laseroptek.raman.ui.common.button

import android.content.res.Configuration
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
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.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.laseroptek.raman.R
import com.laseroptek.raman.ui.theme.RobotoTypography
import com.laseroptek.raman.utils.ext.dropShadow
import com.laseroptek.raman.utils.ext.noRippleClickable
import com.laseroptek.raman.utils.ext.px

@Composable
fun ButtonWithGradientHIconAndText(
    modifier: Modifier = Modifier,
    painter: Painter = painterResource(id = R.drawable.ic_spray),
    title: String = "Purge",
    onClick: () -> Unit = {}
) {
    Row(
        modifier = modifier
            .noRippleClickable {
                onClick.invoke()
            },
        horizontalArrangement = Arrangement.Center,
        verticalAlignment = Alignment.CenterVertically
    ) {
        Image(
            modifier = Modifier.size(14.px.dp, 14.px.dp),
            painter = painter,
            contentDescription = null,
            contentScale = ContentScale.Crop,
            colorFilter = ColorFilter.tint(Color.Black)
        )

        Spacer(modifier = Modifier.width(4.px.dp))

        Text(
            text = title,
            style = RobotoTypography.bodySmall,
            fontWeight = FontWeight.Thin,
            fontSize = 14.px.sp,
            color = Color.Black,
        )
    }

}

@Preview(
    uiMode = Configuration.UI_MODE_NIGHT_NO,
    showBackground = false
)
@Composable
fun PreviewButtonWithGradientHIconAndText() {
    Column (
        modifier = Modifier.background(Color.White),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center,
    ) {
        ButtonWithGradientHIconAndText(
            modifier = Modifier
                .size(85.px.dp, 32.px.dp)
                .clip(RoundedCornerShape(7.px.dp))
                .background(
                    brush = Brush.linearGradient(
                        colorStops = arrayOf(
                            0.0f to Color(43, 20, 63),
                            1.0f to Color(123, 74, 152),
                        )
                    )
                )
                .border(1.5.px.dp, color = Color(92, 47, 130), shape = RoundedCornerShape(7.px.dp))
                .dropShadow(
                    shape = RoundedCornerShape(7.px.dp),
                    color = Color(243,205,81).copy(alpha = 0.2f),
                    blur = 3.5.px.dp,
                    offsetX = 0.px.dp,
                    offsetY = 0.px.dp,
                    spread = 0.px.dp
                )
                .dropShadow(
                    shape = RoundedCornerShape(7.px.dp),
                    color = Color(0,0,0).copy(alpha = 0.1f),
                    blur = 3.5.px.dp,
                    offsetX = 1.75.px.dp,
                    offsetY = 1.75.px.dp,
                    spread = 0.px.dp
                ),
            title = "Purge",
            painter = painterResource(id = R.drawable.ic_purge),
            onClick = {
                // Perform action when button is clicked
            }
        )

        Spacer(modifier = Modifier.height(16.px.dp))

        ButtonWithGradientHIconAndText(
            modifier = Modifier
                .size(76.px.dp, 32.px.dp)
                .clip(RoundedCornerShape(7.px.dp))
                .background(
                    brush = Brush.linearGradient(
                        colorStops = arrayOf(
                            0.0f to Color(47, 51, 57),
                            1.0f to Color(83, 88, 97),
                        )
                    )
                )
                .border(1.5.px.dp, color = Color(92, 99, 107), shape = RoundedCornerShape(7.px.dp))
                .dropShadow(
                    shape = RoundedCornerShape(7.px.dp),
                    color = Color(243,205,81).copy(alpha = 0.2f),
                    blur = 3.5.px.dp,
                    offsetX = 0.px.dp,
                    offsetY = 0.px.dp,
                    spread = 0.px.dp
                )
                .dropShadow(
                    shape = RoundedCornerShape(7.px.dp),
                    color = Color(0,0,0).copy(alpha = 0.1f),
                    blur = 3.5.px.dp,
                    offsetX = 1.75.px.dp,
                    offsetY = 1.75.px.dp,
                    spread = 0.px.dp
                ),
            title = "Refresh",
            painter = painterResource(id = R.drawable.ic_refresh),
            onClick = {
                // Perform action when button is clicked
            }
        )

        Spacer(modifier = Modifier.height(16.px.dp))

        ButtonWithGradientHIconAndText(
            modifier = Modifier
                .size(76.px.dp, 32.px.dp)
                .clip(RoundedCornerShape(7.px.dp))
                .background(
                    brush = Brush.linearGradient(
                        colorStops = arrayOf(
                            0.0f to Color(82, 63, 2),
                            1.0f to Color(204, 156, 0),
                        )
                    )
                )
                .border(1.5.px.dp, color = Color(142, 110, 5), shape = RoundedCornerShape(7.px.dp))
                .dropShadow(
                    shape = RoundedCornerShape(7.px.dp),
                    color = Color(243,205,81).copy(alpha = 0.2f),
                    blur = 3.5.px.dp,
                    offsetX = 0.px.dp,
                    offsetY = 0.px.dp,
                    spread = 0.px.dp
                )
                .dropShadow(
                    shape = RoundedCornerShape(7.px.dp),
                    color = Color(0,0,0).copy(alpha = 0.1f),
                    blur = 3.5.px.dp,
                    offsetX = 1.75.px.dp,
                    offsetY = 1.75.px.dp,
                    spread = 0.px.dp
                ),
            title = "Test",
            painter = painterResource(id = R.drawable.ic_spray),
            onClick = {
                // Perform action when button is clicked
            }
        )
    }

}
