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

// Removed: import android.graphics.drawable.shapes.Shape 
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
// import androidx.compose.foundation.layout.PaddingValues // Not used in this version
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.IconButton // Using Material 3
// import androidx.compose.material3.Button // Alternative with more customization - Not used in this version
// import androidx.compose.material3.ButtonDefaults // Not used in this version
// import androidx.compose.material3.MaterialTheme // Not used in this version
import androidx.compose.runtime.Composable
// import androidx.compose.ui.Alignment // Not used in this version
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape // Added for parameter type
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.laseroptek.raman.R
import com.laseroptek.raman.utils.ext.px

@Composable
fun ImageButton(
    onClick: () -> Unit,
    painter: Painter,
    modifier: Modifier = Modifier,
    shape: Shape = CircleShape, // Added shape parameter
    buttonSize: Dp = 40.px.dp, // Overall size of the button
    iconSize: Dp = 40.px.dp,   // Size of the icon inside the button
    backgroundColor: Color = Color.Transparent, // Optional background
    borderColor: Color? = null, // Optional border color
    borderWidth: Dp = 0.dp, // Optional border width
    contentDescription: String? = null // For accessibility
) {
    Box(
        modifier = modifier
            .size(buttonSize, buttonSize)
            .clip(shape) // Use the shape parameter
            .background(backgroundColor)
            .then(
                if (borderColor != null) {
                    Modifier.border(borderWidth, borderColor, shape) // Use the shape parameter
                } else {
                    Modifier
                }
            )
    ) {
        IconButton(
            onClick = onClick,
            modifier = Modifier.matchParentSize() // Make IconButton fill the Box
        ) {
            Image(
                painter = painter,
                contentDescription = contentDescription,
                contentScale = ContentScale.Crop, // Or Crop, depending on your image
                modifier = Modifier.size(iconSize)
            )
        }
    }
}


@Preview(showBackground = false)
@Composable
fun ImageButtonPreview() {
    //val examplePainter = painterResource(id = R.drawable.ic_purge) // Replace with your actual drawable

    ImageButton(
        onClick = { /*TODO*/ },
        painter = painterResource(id = R.drawable.ic_purge_btn) ,
        // You can now optionally pass a different shape here for testing:
        // shape = RoundedCornerShape(8.dp), 
        //contentDescription = "Android Icon Button",
        //borderColor = Color.DarkGray,
        //borderWidth = 2.dp
    )
}
