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

import android.content.res.Configuration
import androidx.compose.foundation.Image
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.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.laseroptek.raman.R
import com.laseroptek.raman.ui.theme.RacingSansOneTypography
import com.laseroptek.raman.ui.theme.RobotoTypography
import com.laseroptek.raman.utils.ext.noRippleClickable
import com.laseroptek.raman.utils.ext.px

@Composable
fun ButtonWithHIconAndText(
    modifier: Modifier = Modifier.size(483.px.dp, 174.px.dp),
    text: String,
    style: TextStyle = RacingSansOneTypography.titleSmall,
    fontSize: TextUnit = 60.px.sp,
    textColor: Color = Color.Black,
    backgroundColor: Color = Color(255,204,2),
    roundedCornerShape: RoundedCornerShape = RoundedCornerShape(topStart = 110.px.dp, topEnd = 24.px.dp, bottomStart = 24.px.dp, bottomEnd = 24.px.dp),
    trailingIcon: @Composable() () -> Unit ={},
    leadingIcon: @Composable() () -> Unit ={},
    isDisabled: MutableState<Boolean> = mutableStateOf(false),
    onClick: () -> Unit = {}
) {
    Surface(
        shadowElevation = 4.px.dp,
        shape = roundedCornerShape,
        color = backgroundColor,
    ){
        Row(
            modifier = if (! isDisabled.value) modifier.noRippleClickable(onClick = onClick) else modifier,
            horizontalArrangement = Arrangement.Center,
            verticalAlignment = Alignment.CenterVertically
        ){
            leadingIcon()
            Spacer(Modifier.width(24.px.dp))
            //Text(text, color = textColor, fontWeight = FontWeight.Bold,)
            Text(
                text = text,
                style = RobotoTypography.bodyMedium.copy(
                    textAlign = TextAlign.End,
                    fontWeight = FontWeight.Medium,
                ),
                fontSize = fontSize,
                color = textColor,
            )
            trailingIcon()
        }
    }
}

@Preview(
    uiMode = Configuration.UI_MODE_NIGHT_NO,
    showBackground = false
)

@Composable
fun PreviewButtonWithHIconAndText() {
    Column(
        modifier = Modifier.size(483.px.dp, 174.px.dp),
        horizontalAlignment = Alignment.CenterHorizontally) {
        ButtonWithHIconAndText(
            text = "STANDBY",
            leadingIcon = {
                //Icon(Icons.Filled.Star, contentDescription = null, tint = Color.White)
                Image(
                    painter = painterResource(id = R.drawable.ic_play),
                    contentDescription = null,
                    modifier = Modifier.size(49.px.dp)
                )
            },
            onClick = {
                // Perform action when button is clicked
            }
        )
    }

}
