package com.laseroptek.raman.ui.screens.engineer.energy

import android.content.res.Configuration
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.fillMaxWidth
import androidx.compose.foundation.layout.height
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.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.res.stringResource
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.dp
import androidx.compose.ui.unit.sp
import com.laseroptek.raman.R
import com.laseroptek.raman.const.validHandPieceTypes
import com.laseroptek.raman.ui.theme.PretendardTypography
import com.laseroptek.raman.ui.theme.RobotoTypography
import com.laseroptek.raman.utils.ext.px


@Composable
fun HandPieceView(
    //onClick: (Int) -> Unit = {},
    hpType: Int = 1,    // handpiece type no (1..n-1)
    title:String = stringResource(R.string.h_p_title)
) {
    Column(
        Modifier
            .fillMaxWidth()
            .height(52.px.dp)
    ) {
        // HandPiece title
        Row(
            Modifier
                .fillMaxWidth()
                .height(22.px.dp)
                .clip(RoundedCornerShape(topStart = 11.px.dp, topEnd = 11.px.dp))
                .background(Color.Black),
            horizontalArrangement = Arrangement.Center,
            verticalAlignment = Alignment.CenterVertically
        ) {
            Text(
                text = title,
                color = Color.White,
                style = PretendardTypography.titleSmall,
                fontWeight = FontWeight.ExtraLight,
                fontSize = 12.px.sp,
                textAlign = TextAlign.Center,
                lineHeight = 22.px.sp
            )
        }

        // HandPiece value
        Row(
            modifier = Modifier
                .fillMaxWidth()
                .height(30.px.dp)
                .border(1.dp, color = Color.Gray, shape = RectangleShape),
            horizontalArrangement = Arrangement.SpaceBetween,
            verticalAlignment = Alignment.CenterVertically
        ) {
            for (i in 1 .. validHandPieceTypes.size) {
                Column(
                    Modifier
                        //.noRippleClickable(onClick = { onClick.invoke(i) })
                        .fillMaxWidth()
                        .weight(1f)
                        .height(31.px.dp)
                        .border(0.5.dp, color = Color.Gray, shape = RectangleShape)
                        .background(
                            if (i == hpType) Color(
                                255,
                                204,
                                0
                            ) else Color.White
                        ),
                    verticalArrangement = Arrangement.Center,
                    horizontalAlignment = Alignment.CenterHorizontally
                ) {
                    Text(
                        text = validHandPieceTypes[i - 1],
                        color = Color.Black,
                        style = RobotoTypography.bodyMedium,
                        fontWeight = FontWeight.ExtraLight,
                        fontSize = 14.px.sp,
                        textAlign = TextAlign.Center,
                        lineHeight = 31.px.sp
                    )
                }
            }
        }
    }
}


@Preview(
    uiMode = Configuration.UI_MODE_NIGHT_NO,
    showBackground = false,
    //device = "spec:width=640dp,height=1080dp,dpi=150,isRound=false,chinSize=0dp,orientation=landscape"
)
@Composable
fun PreviewHandPieceView() {
    Row {
        HandPieceView(
            hpType = 0  // 1..n-1
        )
        Spacer(modifier = Modifier.height(10.px.dp))
        HandPieceView(
            hpType = 1
        )
        Spacer(modifier = Modifier.height(10.px.dp))
        HandPieceView(
            hpType = 3
        )
        Spacer(modifier = Modifier.height(10.px.dp))
        HandPieceView(
            hpType = 5
        )
    }
}